anyone here successfully import queries from the g...
# orm-help
h
anyone here successfully import queries from the generated schema and used them in real queries? I have got a data type
Order
with a unique field
id
. I imported
Query.order
from
prisma.graphql
, then implemented the resolvers as:
Copy code
orders: (_, args, { prisma }) => prisma.order(arg),
but it fails, shows
Copy code
"Variable '$where' expected value of type 'OrderWhereUniqueInput!' but got: {\"where\":{\"id\":\"cjn1adt3m03ao0875rf9fgh7w\"}}. Reason: 'where' Field 'where' is not defined in the input type 'OrderWhereUniqueInput'. (line 1, column 8):\nquery ($where: OrderWhereUniqueInput!)
Then I changed it to
Copy code
orders: (_, args, { prisma }) => prisma.order(args.where),
It seems that
prisma.order()
takes a
where
object. What aboud
prisma.orders()
? I digged into
prisma.graphql
and found out that the
orders
query takes many arguments. How should I pass down the arguments? Should I pass the whole
args
to the function? If so, wouldn't it be inconsistent because the two functions take different arguments?
n
hey there, the GraphQL API and generated Client API differs (see https://github.com/prisma/prisma/issues/3185)
as you correctly found out
wherever a query or mutation only takes in one argument, the wrapper is removed in the client. in the case of
prisma.order
the wrapper
where
is removed. however,
prisma.orders
takes multiple arguments, so the wrappers are still there.
Should I pass the whole
args
to the function?
yup
If so, wouldn't it be inconsistent because the two functions take different arguments?
that's one way to see it, the other side of the coin is that it's a simplification of the API where possible
I would love to hear your input on the issue I shared 🙂 we are actively collecting feedback on this, and will in time rely on the feedback in GitHub to make a decision here.
h
Thanks for the quick reply! I think the inconsistency will not be a problem for us, but if I could wish, I would like to have both ways viable 😄 Though I know this would be a big problem in overloading both cases with single object input.
d
Are you using JS or TS? 🙂