Created
February 25, 2022 23:02
-
-
Save BrutalSimplicity/e3a0acd6a7d0f66d5de9417604bce9b4 to your computer and use it in GitHub Desktop.
Sparql Typescript DSL Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('should perform multi-path traversal query with criteria at multiple levels', async () => { | |
const actual = await query.executeQuery({ | |
select: ['id', 'name'], | |
where: { | |
match: { and: { type: createIriValue('abound', 'Customer'), id: 'bb27d6a5-091b-4763-9246-0d9e963fd7f8' } }, | |
}, | |
relation: 'owns', | |
buildings: { | |
select: ['id', 'name'], | |
floors: [ | |
'hasPart', | |
{ | |
select: ['id', 'name'], | |
rooms: [ | |
'hasPart', | |
{ | |
select: ['id', 'name'], | |
relation: 'isLocationOf', | |
assets: { | |
select: ['id', 'name'], | |
}, | |
}, | |
], | |
assets: [ | |
'isLocationOf', | |
{ | |
select: ['id', 'name'], | |
}, | |
], | |
}, | |
], | |
assets: [ | |
'isLocationOf', | |
{ | |
select: ['id', 'name'], | |
relation: 'hasLocation', | |
where: { match: { and: { type: createIriValue('abound', 'Test') } } }, | |
spaces: { | |
select: ['id', 'name'], | |
}, | |
}, | |
], | |
}, | |
}); | |
const expected = [ | |
{ | |
id: 'bb27d6a5-091b-4763-9246-0d9e963fd7f8', | |
name: 'Customer Alpha', | |
buildings: [ | |
{ | |
id: '9aadd180-d9b9-4199-a215-d3ad2908ce96', | |
name: 'Building One', | |
floors: [ | |
{ | |
id: '75c20343-e5f6-4317-a347-341801f15ddb', | |
name: 'Floor 1', | |
rooms: [ | |
{ | |
id: '6730d748-69a3-4c6e-b23f-d821537d89aa', | |
name: 'Room A', | |
assets: [ | |
{ | |
id: 'a496a6e6-ffde-47d7-9e53-cf8e7c689c1b', | |
name: 'Asset A', | |
}, | |
{ | |
id: 'c4304c10-c291-4471-bbd8-e682a51b020a', | |
name: 'Asset F for Room A', | |
}, | |
{ | |
id: '8fdb7cce-8b9b-44e9-9c2a-5fcabfc73470', | |
name: 'Asset E for Room A', | |
}, | |
], | |
}, | |
], | |
assets: [ | |
{ | |
id: '70524113-0647-4ffd-af42-ef10d7e325dfb', | |
name: 'Asset D for Building and Floor', | |
}, | |
], | |
}, | |
], | |
assets: [ | |
{ | |
id: 'f3ff067e-2594-4b71-9475-b50caa0c73a5', | |
name: 'Asset B for Building', | |
spaces: [ | |
{ | |
id: '9aadd180-d9b9-4199-a215-d3ad2908ce96', | |
name: 'Building One', | |
}, | |
], | |
}, | |
{ | |
id: '3e0ed69d-49aa-431b-b9de-7cccde9a69bd', | |
name: 'Asset C for Building', | |
spaces: [ | |
{ | |
id: '9aadd180-d9b9-4199-a215-d3ad2908ce96', | |
name: 'Building One', | |
}, | |
], | |
}, | |
{ | |
id: '70524113-0647-4ffd-af42-ef10d7e325dfb', | |
name: 'Asset D for Building and Floor', | |
spaces: [ | |
{ | |
id: '9aadd180-d9b9-4199-a215-d3ad2908ce96', | |
name: 'Building One', | |
}, | |
{ | |
id: '75c20343-e5f6-4317-a347-341801f15ddb', | |
name: 'Floor 1', | |
}, | |
], | |
}, | |
], | |
}, | |
], | |
}, | |
]; | |
expect(actual).toEqualInAnyOrder(expected); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment