nestjs-graphql-connection
nestjs-graphql-connection copied to clipboard
Allow nodes to be Unions
Awesome library!
Is there a way for nodes to be a Union or ObjectType (it only allows this right now)? The relay spec itself allows this: https://relay.dev/graphql/connections.htm#sec-Node
I would also love to see an example with GraphQL Union Types
Unions should work but you have to define your own Edge class from scratch, it's not supported by extending createEdgeType() because that expects to be passed a class constructor.
Your Edge class should implements EdgeInterface<YourUnionType> and contain node and cursor properties, with node being typed and decorated to match your union. You can look at what createEdgeType does here as a basis: https://github.com/equalogic/nestjs-graphql-connection/blob/master/src/type/Edge.ts#L16
The above workaround is no longer required in v1.1.0
You can now pass a union type for your nodes directly to createEdgeType().