I am curious if the new GraphQL API supports union types? I could not seem to find it in the documentation here, but it seems like it has been mentioned before.
Here is an example of a way I’d like to specify the schema (if another strategy is better, please let me know!):
schema.graphql
type A {
...other fields
bs_and_cs: [Thing]
}
type B {
...fields
}
type C {
...fields
}
union Thing = B | C
If I have a schema like this (with more specific names of course), and try to post it to a locally running instance with: curl -X POST localhost:8080/admin/schema -d '@schema.graphql', the parser seems to have issues with the union type(s): couldn't rewrite mutation updateGQLSchema because input:1: Unexpected Name \"C\"\n"
It seems as though an interface type might work for a case where there are similar fields between B and C. Though, a union type might be more ideal.
interface Thing {
similar_field: String
}
type A {
...other fields
things: [Thing]
}
type B implements Thing {
...fields
}
type C implements Thing {
...fields
}
Union types aren’t supported yet but you can expect support for it soon (sometime next month). Interface types are supported as you would have found out.
Hi folks, just curious to know any updates on “union”.
We are in the process of moving our infrastructure to dgraph and union is one of the last hurdles we have.
Thank you!
Hi @jana , Happy to hear that you are moving your infrastructure to Dgraph.
We will start working on UNION soon and it will be added in at max 6-8 weeks .
Yes, interfaces work. You can have the above schema. You can’t create nodes of interface Thing, but you can create nodes of type B and C. Once created, they can behave as nodes of interface Thing.