Gaurav
04/30/2019, 2:56 PMgraphql-code-generator
and prisma
type mismatch on returning promise.
That is, for this field resolver:
customer: async (root, args, context) => {
try {
await ifCustomerOwnsThisResource(context, {
cartItems_some: {
id: root.id
}
});
return await context.prisma.customerCartItem({ id: root.id }).customer();
} catch (error) {
console.error(error);
}
},
I am getting this error:
src/resolvers/cartResolvers.ts:25:3 - error TS2322: Type '(root: CustomerCartItem, args: {}, context: IContext) => Promise<Customer>' is not assignable to type 'Resolver<Customer, CustomerCartItem, IContext, {}>'.
Type '(root: CustomerCartItem, args: {}, context: IContext) => Promise<Customer>' is not assignable to type 'ResolverFn<Customer, CustomerCartItem, IContext, {}>'.
Type 'Promise<Customer>' is not assignable to type 'Customer | Promise<Customer>'.
Type 'Promise<import("G:/graphql/prod/graphql-server/src/generated/prisma-client-ts/index").Customer>' is not assignable to type 'Promise<import("G:/graphql/prod/graphql-server/src/generated/resolvers-types").Customer>'.
From what I get, prisma
returns interface CustomerPromise
for chained query, while Promise<Customer>
is expected as return expression by graphql-code-generator
. How to fix that?divyendu
04/30/2019, 3:00 PMdivyendu
04/30/2019, 3:00 PMGaurav
04/30/2019, 3:03 PMgraphqlgen
but graphql-code-generator
(had struggles with graphqlgen
2 months ago, didn't try it since.
- I think second suggestion is local to graphqlgen
too!Harshit
05/01/2019, 4:36 PMreturn await context.prisma.customerCartItem({ id: root.id }).customer();
to return context.prisma.customerCartItem({ id: root.id }).customer();
Gaurav
05/03/2019, 6:01 PMawait
is necessary. (Correct me if wrong) Here in the return statement, I do understand what you're saying, and will correct to eliminate await
in those places.
But I don't think that solves this issue, since prisma-client
returns a promise only. Doesn't it?