Skip to content
Snippets Groups Projects
Commit 4621c186 authored by thijsheijden's avatar thijsheijden
Browse files

Added check to make sure entityFrom and entityTo can be less than -1

parent fefab2e2
No related branches found
No related tags found
No related merge requests found
......@@ -92,25 +92,19 @@ func createQuery(jsonQuery *entity.QueryParsedJSON) *string {
for i, relation := range jsonQuery.Relations {
relationName := fmt.Sprintf("r%v", i)
if relation.EntityFrom != -1 {
if relation.EntityFrom >= 0 {
// if there is a from-node
// create the let for this node
fromName := fmt.Sprintf("n%v", relation.EntityFrom)
// Check if this entity index exists
if entity := &jsonQuery.Entities[relation.EntityFrom]; entity != nil {
ret += *createNodeLet(entity, &fromName)
}
ret += *createNodeLet(&jsonQuery.Entities[relation.EntityFrom], &fromName)
ret += *createRelationLetWithFromEntity(&relation, relationName, &jsonQuery.Entities, jsonQuery.Limit)
} else if relation.EntityTo != -1 {
} else if relation.EntityTo >= 0 {
// if there is only a to-node
toName := fmt.Sprintf("n%v", relation.EntityTo)
// Check if this entity index exists
if entity := &jsonQuery.Entities[relation.EntityTo]; entity != nil {
ret += *createNodeLet(entity, &toName)
}
ret += *createNodeLet(&jsonQuery.Entities[relation.EntityTo], &toName)
ret += *createRelationLetWithOnlyToEntity(&relation, relationName, &jsonQuery.Entities, jsonQuery.Limit)
// Add this relation to the list
......
......@@ -550,3 +550,51 @@ func TestNoRelationsField(t *testing.T) {
cleanedResult = strings.ReplaceAll(cleanedResult, "\t", "")
assert.Equal(t, correctConvertedResult, cleanedResult)
}
func TestEntityFromLowerThanNegativeOneInRelation(t *testing.T) {
// Setup for test
// Create query conversion service
service := NewService()
query := []byte(`{
"return": {
"entities": [
0
],
"relations": [
0
]
},
"entities": [
{
"type": "airports",
"constraints": [
{
"attribute": "city",
"value": "San Francisco",
"dataType": "text",
"matchType": "exact"
}
]
}
],
"relations": [
{
"type": "flights",
"depth": {
"min": 1,
"max": 1
},
"entityFrom": -4,
"entityTo": 0,
"constraints": []
}
],
"limit": 5000
}`)
_, err := service.ConvertQuery(&query)
// Assert that there is no error
assert.NoError(t, err)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment