Union Type - A type value of multiple types


(Pepo) #1

I am building a schema in which one node can have one edge to one other node which can be of different types.

I wonder how should I specify this in the type system.

Does GraphQL± support Union Types?

Would this work?

type Person {
    name: string
    works_for: [Person | Company]
}

type Company {
    name: string
}

Or maybe I should leave it as a generic uid value?

type Person {
    name: string
    works_for: [uid]
}

But then, I loose the expand(_all_) functionality when querying, isn’t?


(Michel Conrado) #2

Nope, We don’t have a convention about the Type Schema. And this is in the very early stages, so still have things to come. Open an issue if you find it necessary.

leave like this. If it don’t work, open a bug issue.

As far I know you only loose the expand all functionality if the mutation itself doesn’t have the <dgraph.type> specified and also doesn’t have a related type in the Type Schema.


(Michael Compton) #3

@Pepo we are currently building out a native support for GraphQL in Dgraph. That will have union types.