nexus-plugin-prisma icon indicating copy to clipboard operation
nexus-plugin-prisma copied to clipboard

Type problem when creating entity

Open BjoernRave opened this issue 4 years ago • 1 comments

After the upgrade to 0.25.0 I get a lot of type problems, like this one:

(property) tags?: string | Prisma.ClientCreatetagsInput | string[]
Type '{ set?: string[]; }' is not assignable to type 'string | ClientCreatetagsInput | string[]'.
  Type '{ set?: string[]; }' is not assignable to type 'ClientCreatetagsInput'.
    Property 'set' is optional in type '{ set?: string[]; }' but required in type 'ClientCreatetagsInput'.ts(2322)
index.d.ts(23714, 5): The expected type comes from property 'tags' which is declared here on type 'ClientCreateInput'

In this case it looks something like this:

t.field('createOneClient', {
  type: 'Client',
  args: {
    tags: arg({ type: 'ClientCreatetagsInput' }),
  },
  resolve: async (_parent, { tags }, ctx) => {
  const client = await ctx.prisma.client.create({data: { tags }})
  },
})

So, for the inputObject I am using the type generated, but it still complains

BjoernRave avatar Dec 02 '20 19:12 BjoernRave

Changing all instances of set?: to set: in the nexus typegen solved all my errors so this only seems to be happening for models with scalar lists. Obviously, this isn't a solution but confirmed the problem is with the set.

TrevHeath avatar Dec 19 '20 22:12 TrevHeath