prisma-labs/graphqlgen

Error when trying to type safe Prisma in context

loaiShaheen opened this issue · 4 comments

Description

When using Prisma in the context, it does not work for any resolver except for fetching a list.

Steps to reproduce

My schema.graphql just consists of importing schema from the generated Prisma schema.

Expected results

Prisma in the context should be type safe with no errors.

Actual results

This is the ts error I get when trying to fetch a single object:

Argument of type 'OfferWhereUniqueInput' is not assignable to parameter of type 'AtLeastOne<{ id: string | number; }, { id: Pick<{ id: string | number; }, "id">; }>'

This is the ts error I get when trying to create an object:

Argument of type 'import("/generated/graphqlgen").MutationResolvers.OfferCreateInput' is not assignable to parameter of type 'import("/generated/prisma-client/index").OfferCreateInput'.

Versions

  • graphqlgen:0.6.0-rc1
  • OS name and version:MacOS Mojave 10.14.2

Hey @loaiShaheen, can you construct a minimal repro and place it in a public git repository?

Hi @jasonkuhrt, I uploaded the repository. I found that the error happens when ({ data }) is being passed into the resolver (e.g. ctx.prisma.createUser({ data })). When passing ({ where }) it can be deconstructed into { id: where.id } and will not give an error, or in the case where a type has multiple unique fields it will not give an error at all and doesn’t need to be deconstructed. After searching through the code I found that the error given by the data argument is coming from the difference in the interface between graphqlgen.ts and prisma-client/index.ts.

In graphqlgen.ts the UserCreateInput interface looks like this:

export interface UserCreateInput {
    name?: string | null;
    game?: GameCreateOneInput | null;
}

While in prisma-client/index.ts the UserCreateInput interface looks like this:

export interface UserCreateInput {
    name?: String;
    game?: GameCreateOneInput;
}

This error also only occurs when the type has relation fields

Thanks @loaiShaheen, if I understand correctly, this is a duplicate of #417 and the good place to go is prisma/prisma#3774.

@jasonkuhrt Thanks for your help :)