I have a simple use case but it seems currently impossible to handle in a fancy way using dgraph:
Lets say I have a schema where texts are inserted along with the localization because as we know there are many languages around the world
type Text implements{
text: String! @search(by: [trigram, term, fulltext])
localization: [Localization!]!
}
type Localization implements Metadata {
"""
en-US, ja-JP, it-IT,...
"""
tag: String! @search(by: [hash])
}
type Film
id: String @id
name: Text
}
lets assume the film “Avengers Endgame” and assume that the japanese name is “Avengers Endugamu”. So we have a film which has 2 different names
{
id: avengersendgame
name: //link to the 2 names
}
{
tag: en-US
}
{
text: "Avengers Endgame"
localization: //id of localization en-US
}
{
tag: ja-JP
}
{
text: "Avengers Endugamu"
localization: //id of localization ja-JP
}
what I would like to do is to filter the name and get only the name associated to the localization I need.
In a perfect world the query I would write
queryFilm(filter: {id: {eq: "avengersendgame"}}) {
name(filter: {localization.tag: {eq: "en-US"}}) {
text
}
}
Unfortunately, it seems that filtering on nested property is not something I should think about, so I thought about
queryFilm(filter: {id: {eq: "avengersendgame"}}) {
name @cascade {
text
localization(filter: {tag: {eq: "en-US"}}) {
tag
}
}
}
Now, besides the fact that I’m asking and getting useless information (the localization tag for instance), it starts to become even worse when I try to use aliases to get the name in 2 different localization (for some context, I always need the Japanese name and the name in the language of the client)
queryFilm(filter: {id: {eq: "avengersendgame"}}) {
user_lang_name: name @cascade {
text
localization(filter: {tag: {eq: "en-US"}}) {
tag
}
}
japanese_name: name @cascade {
text
localization(filter: {tag: {eq: "ja-JP"}}) {
tag
}
}
}
returns
{
"errors": [
{
"message": "Dgraph query failed because Dgraph execution failed because : while converting to subgraph: names not allowed multiple times in same sub-query."
}
],
"data": {
"queryFilm": []
}
}
How should I manage this problem? Is the schema wrong? should I wait for some further development of the GraphQL APIs?
Also, the @cascade solution seems to fall off when used in combination with the first filtering both in GraphQL and GraphQL± (the first directive is applied before the cascade, so if the first element fetched do not satisfy the cascade, the query returns an empty result)