nestjs-graphql-connection icon indicating copy to clipboard operation
nestjs-graphql-connection copied to clipboard

Allow nodes to be Unions

Open IgnisDa opened this issue 3 years ago • 2 comments

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

IgnisDa avatar Jul 10 '22 16:07 IgnisDa

I would also love to see an example with GraphQL Union Types

bobsingor avatar Sep 26 '22 11:09 bobsingor

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

sgarner avatar Oct 13 '22 05:10 sgarner

The above workaround is no longer required in v1.1.0

You can now pass a union type for your nodes directly to createEdgeType().

sgarner avatar Apr 30 '25 04:04 sgarner