I recently ran into the issue that if a type implements one or more interfaces, the return type from a DQL query will always be an array. If I know what kind of type I expect can I somehow “pick” the right one from the array manually?
Setup
Assume the following setup:
# Interface
interface TestInterface {
id: ID!
field: String
}
# First type which implements TestInterface
type FirstImplement implements TestInterface {
id: ID!
field: String
firstField: String
}
# Second type which implements TestInterface
type SecondImplement implements TestInterface {
id: ID!
field: String
secondField: String
}
# Type which has TestInterface as field
type HasInterfaceField {
id: ID!
interfaceField: TestInterface
}
Actual behaviour
If I now query HasInterfaceField
for the “dgraph.type”
# DQL Query
{
q(func: uid(0x1)) {
HasInterfaceField.interfaceField {
dgraph.type
}
}
}
the result would be
{
data: {
q: [
0: {
HasInterfaceField.interfaceField {
dgraph.type: [
"FirstImplement",
"TestInterface"
]
}
}
]
}
}
Assuming that HasInterfaceField
has only been assigned with a TestInterface
of type FirstImplement
.
However, if I simply transform this result into GraphQL (so far only by removing the typenames before “.” and replacing “uid” with “id”), the typename for interfaceField
will be TestInterface
instead of FirstImplement
in a GraphQL result.
I hope this makes sense
Any help appreciated!