Hello, I am trying to get desired results with GraphQL, but don’t know how to get it.
Given following schema:
type Restaurant {
id: ID!
name: String! @id @search(by: [hash])
menu_items: [MenuItem!] @hasInverse(field: restaurant)
}
type MenuItem {
id: ID!
name: String! @search(by: [hash,regexp,term])
description: String @search(by: [hash,regexp,term])
restaurant: Restaurant!
}
and mutation:
mutation {
addRestaurant(input:[
{name:"R1"},
{name:"R2"},
{name:"R3"}
]) {
numUids
}
addMenuItem(input:[
{name:"Lasagne",restaurant:{name:"R1"}},
{name:"Lasagne",restaurant:{name:"R2"}},
{name:"Orange Juice",description:"1l bottle",restaurant:{name:"R1"}},
{name:"Orange Juice",restaurant:{name:"R2"}},
{name:"Apple Juice",restaurant:{name:"R2"}},
{name:"Apple Juice",restaurant:{name:"R3"}},
{name:"Steak",restaurant:{name:"R2"}}
]) {numUids}
}
When looking for a juice, I get expected results:
{queryMenuItem(filter:{name:{anyofterms:"juice"}}) {
name
restaurant {
name
}
}}
"data": {
"queryMenuItem": [
{
"name": "Apple Juice",
"restaurant": {
"name": "R3"
}
},
{
"name": "Orange Juice",
"restaurant": {
"name": "R1"
}
},
{
"name": "Orange Juice",
"restaurant": {
"name": "R2"
}
},
{
"name": "Apple Juice",
"restaurant": {
"name": "R2"
}
}
]
},
When filtering for one restaurant:
{queryMenuItem(filter:{name:{anyofterms:"juice"}}) {
name
restaurant (filter:{name:{eq:"R2"}}){
name
}
}}
I get errors “Non-nullable field ‘restaurant’ (type Restaurant!) was not present in result from Dgraph. GraphQL error propagation triggered.”. It can be solver by using @cascade:
{queryMenuItem(filter:{name:{anyofterms:"juice"}}) @cascade {
name
description
restaurant (filter:{name:{eq:"R2"}}){
name
}
}}
But then when I add a “description” (which can be null), I get no results.
Is it possible to get records with name “juice” from “R2” restaurant and with a (optionally null) description in GraphQL query?