Creating union types from prismaObjects #934
Unanswered
DerTimonius
asked this question in
Q&A
Replies: 1 comment
-
It's possible to create union types with prisma objects, but the query optimization won't work quite as well through unions. There is an undocumented trick you need to use with unions (documenting this better has been on my todo list for a while): answers t.field({
type: [AnswerUnion],
resolve: async () => {
const dates = getDateAnswers();
const texts = getTextAnswers();
return [...AnswerDate.addBrand(dates), ...AnswerText.addBrand(texts)];
},
}), |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a project that uses pothos in conjunction with Prisma. Currently, I need to implement a mutation that can return varying types depending on the input - in my case
AnswerText
orAnswerDate
which are bothprismaObjects
.Following the guide on unions I tried to implement a
AnswerUnion
type like this:This is not showing any TypeScript errors at this level, but when I'm trying to use the type I'm getting errors stating that properties like
modelName
are missing, even if I add aresolveTypes
function to the unionType.Is it possible to create
unionTypes
out ofprismaObjects
or is it obligatory to useobjectTypes
in this case?Beta Was this translation helpful? Give feedback.
All reactions