-
How do you create a union type which consists of object types created with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I tried using the return types of |
Beta Was this translation helpful? Give feedback.
-
I found out how to do it 🥳 import { typeBrandKey } from '@pothos/core'
const NodeA = builder.prismaNode({ ... })
const NodeB = builder.prismaNode({ ... })
const MyUnion = builder.unionType('MyUnion', { types: [NodeA, NodeB] })
builder.queryFields((t) => ({
myUnionQuery: t.field({
type: MyUnion,
resolve: () => {
// ...
return {
...prismaNode,
[typeBrandKey]: 'NodeA' // The name of the prisma model that is returned
}
}
}) |
Beta Was this translation helpful? Give feedback.
I found out how to do it 🥳
You need to add
typeBrandKey
when returning the nodes, so that Pothos / GraphQL knows the correct type of the object at runtime.