Do you have a simple example of how to create a Graphql union with the types generated by Payload?
What are you trying to get exactly? It might be easier to recommend something with the full picture
So we have 3 schemas (collections), blogs, podcasts and videos, all of them shared common fields, so I want to create a union type/schema (e.g. type Post = Blog | Podcast | Video) so it can be exposed in the graphql api url and consumed by client.
You would have to make a new custom graphql endpoint
and construct a new type for yourself using the graphQL object passed via the handler with
https://graphql.org/graphql-js/type/#graphqluniontype
something akin to
new GraphQL.GraphQLUnionType()
for the types you can get the generated ones from your
payload.collections['blog'].graphQL.types
instance to use as types here
types: [DogType, CatType],
I wrote a guide here on how to extend the graphql API
https://nouance.io/articles/how-to-extend-graphql-in-payload-with-custom-queries-mutations-and-re-usable-types
Here's the guide in payload docs
https://payloadcms.com/docs/graphql/extendingStar
Discord
online
Get help straight from the Payload team with an Enterprise License.