Union Types in Schema Via GraphQL API?

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"

Thank you!

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
} 

Hey @ttlekich

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.

1 Like

@pawan Thank you so much! I figured they might be still being implemented/tested/etc., but thought I would ask just in case I missed something.

Are we able to use @hasInverse with unions?
@michaelcompton

type {
    favourites: [Things] @hasInverse(id)
}
union Things =  Food | Drink

type Food {
    id: String! @id 
}
type Drink {
    id: String! @id
}

thanks
Ming

1 Like

Hi,

As per discussion above, there’s no unions yet … and no decisions on exactly what will be supported when they arrive.

For interfaces, however, inverses and ids are supported both in the interface and in the implementing types.