What I want to do
I’m trying to create a custom resolver using DQL. This resolver should return data for a union field.
What I did
I’m testing the DQL query in Ratel. However, what I’m finding is that I can only specify fields for one of the object types in the union. If I specify fields for both object types then the query returns no data at all and no errors.
If I query for Phrase
fields:
If I query for Word
fields:
If I query for both Word
and Phrase
fields:
However, if I query for uid
(not restricted to a type), then I get both:
Schema:
type Word @auth(
query: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
add: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
update: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
delete: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
) {
id: ID!
xid: String! @id
start: Float!
end: Float!
text: String! @search(by: [regexp])
paragraph: Paragraph!
transcript: Transcript!
phrase: Phrase
}
type Phrase @auth(
query: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
add: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
update: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
delete: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
) {
id: ID!
paragraph: Paragraph!
words: [Word!] @hasInverse(field: phrase)
start: Float # should be a virtual field, phrase.words[0].start
end: Float # should be a virtual field, phrase.words[words.length - 1].end
}
type Paragraph @auth(
query: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
add: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
update: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
delete: { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
) {
id: ID!
start: Float
end: Float
speaker: Speaker!
text: [Text]
words: [Word!] @hasInverse(field: paragraph)
phrases: [Phrase] @hasInverse(field: paragraph)
transcript: Transcript!
}
Dgraph metadata
dgraph version
21.03