How do you add orphan types to the schema?

We’re creating a schema via new GraphQLSchema(), which is then passed into new ApolloServer()

One of our fields is a GraphQL interface (e.g. interface Vehicle)

We then have types that implement this interface (e.g. type Car implements Vehicle)

However, since only the interface and not the types themselves are directly returned, those types do not appear in the generated schema

Other GraphQL solutions that I’ve used allow for these “orphan types” to be added to the schema, but I can’t figure out how to do it via the current setup, so any help would be much appreciated

Figured it out - the orphan types just need to be added to the types array inside the schema config, e.g.

new GraphQLSchema({
    query: QueryType,
    mutation: MutationType,
    types: [OrphanType]
});
1 Like