Created
February 25, 2022 23:07
-
-
Save BrutalSimplicity/d203611841726702bff0fbb6b62a5e2b to your computer and use it in GitHub Desktop.
SPARQL DSL Typescript Test
This file contains hidden or 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 build relationship query with node traversals', () => { | |
const query: Query = { | |
select: ['id', 'name'], | |
where: { | |
match: { | |
and: { | |
id: ['45a4d510-adb8-41d1-a34e-557ed6b88309', 'ed79b15e-f60b-4cc6-877b-c653606e68a3'], | |
}, | |
}, | |
}, | |
relation: 'owns', | |
site: { | |
relation: 'hasPart', | |
building: { | |
select: ['id', 'name'], | |
relation: 'hasPart', | |
floor: { | |
select: ['id', 'name'], | |
relation: 'hasPart', | |
room: { | |
select: ['id', 'name'], | |
relation: 'isLocationOf', | |
asset: { | |
select: ['id', 'name'], | |
}, | |
}, | |
}, | |
}, | |
}, | |
}; | |
const context = createQueryContextTree(query); | |
const actual = buildRelationshipQuery(context).expressions; | |
console.log(actual); | |
const expected = [ | |
'?_ abound:id ?_criteria_id .', | |
'FILTER (?_criteria_id IN ("45a4d510-adb8-41d1-a34e-557ed6b88309","ed79b15e-f60b-4cc6-877b-c653606e68a3"))', | |
'OPTIONAL { ?_ abound:id ?_id . }', | |
'OPTIONAL { ?_ rdfs:label ?_name . }', | |
'OPTIONAL { ?_ abound:owns ?_site_ .\n' + | |
'OPTIONAL { ?_site_ brick:hasPart ?_site_building_ .\n' + | |
'OPTIONAL { ?_site_building_ abound:id ?_site_building_id . }\n' + | |
'OPTIONAL { ?_site_building_ rdfs:label ?_site_building_name . }\n' + | |
'OPTIONAL { ?_site_building_ brick:hasPart ?_site_building_floor_ .\n' + | |
'OPTIONAL { ?_site_building_floor_ abound:id ?_site_building_floor_id . }\n' + | |
'OPTIONAL { ?_site_building_floor_ rdfs:label ?_site_building_floor_name . }\n' + | |
'OPTIONAL { ?_site_building_floor_ brick:hasPart ?_site_building_floor_room_ .\n' + | |
'OPTIONAL { ?_site_building_floor_room_ abound:id ?_site_building_floor_room_id . }\n' + | |
'OPTIONAL { ?_site_building_floor_room_ rdfs:label ?_site_building_floor_room_name . }\n' + | |
'OPTIONAL { ?_site_building_floor_room_ brick:isLocationOf ?_site_building_floor_room_asset_ .\n' + | |
'OPTIONAL { ?_site_building_floor_room_asset_ abound:id ?_site_building_floor_room_asset_id . }\n' + | |
'OPTIONAL { ?_site_building_floor_room_asset_ rdfs:label ?_site_building_floor_room_asset_name . } } } } } }', | |
]; | |
expect(actual).toEqual(expected); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment