Prisma and Interface issues #940
Replies: 1 comment 1 reply
-
This is definitely a complex case... I don't have a perfect solution here, but something that may help is that you can pass in a default selection to const query = queryFromInfo({
select: { remarkId: true },
context,
info,
typeName: typename,
path: ['reference'],
}); This is just adding to your workaround, and not a real solution. It's pretty challenging for Pothos to resolve this, because the prisma query needs to be calculated before the data is resolved, so it can't know the concrete type of the interface, unless it's hinted at though an argument (eg, your example the typename is encoded in the ID, but pothos wouldn't know that). Putting selections on interface fields is also kinda tricky, because implementors of interfaces may be completely different, using different tables, or may not even be prisma objects. You can manually add this info tho (you just need to add an extension with a select function to your field (https://github.com/hayes/pothos/blob/main/packages/plugin-prisma/src/index.ts#L57-L72) remark: t.field({
type: ...,
resolve: ...,
extensions: {
pothosPrismaSelect: () => ({ remarkId: true })
}
}) This is using internal functionality that I won't guarantee will work forever, but I also don't have any plans to change how this works in the future. I'm not 100% sure this works, because since I haven't tested it, but hopefully this gives you an ideas for next steps |
Beta Was this translation helpful? Give feedback.
-
I believe I may have discovered a "bug" with the prisma plugin and nested interfaces.
This is a fairly complicated issue and it's not obvious to me how this could be fixed, given the way graphql-tools resolves abstract types (e.g. Interfaces).
Here's a type
Ticket
that implements some interfaces, including theHasRemark
interface.Consider the following query to fetch "tickets" their associated remarks and their links.
Example response:
The
Remark
id is resolved correctly in the initial Ticket, but in the linked Ticket, theHasRemark
InterfaceRefremark
field receives aLinkable
as the parent, not the complete Ticket which should include the selected fields includingremarkId
.When resolving the Linkable into a Ticket, each field resolver is called separately in parallel. The resolver for the
title
field on the Ticket is resolved via Prisma automatically by the Prisma Plugin, but theremark
field here is resolved on this InterfaceRefThere is a workaround for this, but it's not ideal. In the resolver for the field that returns an interface, you can return the entire object and not just the interface fields.
As you can see, you cannot actually use the queryFromInfo here either because it doesn't have any way of knowing that it needs the remarkId field.
I guess the way to solve this within pothos would be to allow interface fields to contain a
select
with a required field and then limit them to being used on Prisma objects. I'm not sure how that would work though...Beta Was this translation helpful? Give feedback.
All reactions