-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use with explicit many-to-many models (error in Edit view due to Input) #32
Comments
And as is so often the case, after hours of debugging I find the issue right after submitting the github issue. It seems that the problem stems from the way Prisma recommends naming intermediate many-to-many models. If the related models are I can get around this by changing the name of my model. Now that I know what's causing it, I'm wondering what the right solution is though. It seems like perhaps queryAllName should be guaranteed to be different from queryName, even if queryName is plural by default? The challenge of "naming things" strikes again... |
haha, story of my life.
So it should be CategoriesOnPostss ? with two s? I think that should be an easy fix. Edit: we should use the same pluralization that prisma uses, thats currently not the case. |
The example I linked to in the Relation docs does use Even so, regardless of what pluralization strategy ra-data-prisma uses (and pluralize seems like a great option), it seems like maybe there should be some kind of guarantee that the different query (and mutation) names will not conflict. For example, if I named one of my primary models ra-data-prisma uses |
@bennettrogers the problem is, that nexus-plugin-prisma defines these plurals already:
So our pluralizing function should do the same as they do. Probably we could just append a |
It looks like they're struggling with a similar issue: The most recent comment on that issue sounds reasonable to me: nexus-plugin-prisma and ra-data-prisma could just copy what Prisma2 has started doing (appending |
@bennettrogers so we need to wait until that is resolved in nexus-plugin-prisma |
Yes, exactly! Sorry, that's what I should have said. |
upstream PR is open, not sure if it will be merged soon graphql-nexus/nexus-plugin-prisma#804 |
My schema has a few models that are related via many-to-many relations. I'm using the explicit form of the relation in my prisma schema by defining the intermediate model exactly as described in the prisma docs.
As requested in the docs for ra-data-prisma, I'm calling
addCrudResolvers
on all 3 models (both sides of the relation and the intermediate model).On the frontend, I'm also defining resources for all 3 models. My issues start when trying to build out the Edit page for the intermediate model. The
List
view works fine, but when trying to show theEdit
view I'm getting a graphql error that saysError: Variable "$where" got invalid value "MODEL_ID" at "where.id"; Expected type StringFilter to be an object.
This happens with both theEditGuesser
and when trying to define a basicSimpleForm
with only a singleTextField
for the id. (MODEL_ID
actually shows up as the string id of the instance it's trying to fetch).It seems that the Input type expected in the Edit view for the intermediate model is different from the Input type expected by other Edit views, including those for my one-to-many relations. The intermediate model is looking for a
${typeName}WhereInput
, whereas the other models are looking for a${typeName}WhereUniqueInput
. This is causing the error since the dataProvider is passing just theid
for both Inputs, but${typeName}WhereInput
seems to want aStringFilter
.Sorry for the long explanation. I'm not even sure this is the right package to be creating the issue for. If the explanation isn't clear, I'd be happy to try to create a minimal test repo that demonstrates the issue.
Thank you again for your help.
The text was updated successfully, but these errors were encountered: