Setting Up Union Type With Multiple Entities #1198
-
Hi, just wondering the best approach for this as I'm running into a "property not found" error with my setup. I have 3 subgraphs (Products, Content, Listing). In Content I have a union type that includes 2 entities (ProductPayload and ListingPayload):
In the
I thought adding Any suggestions on where I might have the setup wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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 Another option is to remove the need for the resolveType function. You can do this by adding |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for the quick reply! That first option solved the issue, but I may play around with the other options too to see which fits best. |
Beta Was this translation helpful? Give feedback.
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 thebrandWithType
utility function