Skip to content

Setting Up Union Type With Multiple Entities #1198

Answered by hayes
cameronmakarchuk asked this question in Q&A
Discussion options

You must be logged in to vote

There are a number of different options here.

In your resolve type, you can do something like `resolveType: (source) => if ('contentType' in source && source.contentType === 'PRODUCT')

Adding contentType to the returned values in the parent resolver isn't suffient because typescript doesn't know about all the fields that return your union type, it only knows about the types that make up the union type, so you would need to add contentType to all of the individual types that make up the union.

Another option is to remove the need for the resolveType function. You can do this by adding __typename to the returned values instead. Alternatively, you can use the brandWithType utility function

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cameronmakarchuk
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants