graphql-framework-experiment icon indicating copy to clipboard operation
graphql-framework-experiment copied to clipboard

Input type being assigned to a variable of the same type throws "is not assignable to type 'SizeCreateOneWithoutItemInput'" error

Open TheoMer opened this issue 5 years ago • 0 comments

Bug description

So I'm attempting to assign a generated type (connect) to a variable of the same type but receive the following error message in VSCode (1.47.2):

Type '{ connect?: { id?: string | null | undefined; name?: string | null | undefined; } | null | undefined; create?: { createdAt?: any; id: string; ItemVariants?: { connect?: { id?: string | null | undefined; }[] | null | undefined; create?: { ...; }[] | ... 1 more ... | undefined; } | null | undefined; label?: string | ....' is not assignable to type 'SizeCreateOneWithoutItemInput'.

How to reproduce

  1. Created Prisma 1 type:
type Item {
  id: ID! @id
  size: Size!
}

type Size {
  id: ID! @id
  name: String! @unique
  label: String
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

  1. Converting to Prisma 2 I then run:
npx prisma introspect
  1. The following prisma.schema models were generated:
model Item {
  id              String         @id
  sizeId          String
  size            Size           @relation(fields: [sizeId], references: [id])
}

model Size {
  id           String         @id
  label        String?
  name         String         @unique
  Item         Item[]
}
  1. I then created the following objectTypes in graphql.ts:
  schema.objectType({
    name: 'Item',
    definition(t) {
      t.model.id()
      t.model.sizeId()
      t.model.size()
    },
  })

  schema.objectType({
    name: 'Size',
    definition(t) {
      t.model.id()
      t.model.name()
      t.model.label()
      t.model.Item()
    },
  })

which in turn generate the following input types in nexus.graphql:

export type ItemCreateInput = {
  id: string
  size: SizeCreateOneWithoutItemInput
}

input SizeCreateOneWithoutItemInput {
  connect: SizeWhereUniqueInput
  create: SizeCreateWithoutItemInput
}

input SizeWhereUniqueInput {
  id: String
  name: String
}

  1. I then created the following mutationType in graphql.ts
      t.field('createItem', {
        type: "Item",
        nullable: false,
        args: {
          id: schema.idArg({ nullable: false}),
          size: schema.arg({ type: 'SizeCreateOneWithoutItemInput' }),
        },
        resolve: async (_, args, ctx) => {
          return await ctx.db.item.create(
            {
              data: {
                id: args.id,
                size: { ...args.size },
              },
            },
          )
        }
      })

Expected behavior

I expected the type assignment not to throw an error

Environment & setup

  • OS: Windwos X Pro
  • Database: PostgreSQL (Heroku)
  • Node.js version: v10.16.0
  • nexus-plugin-prisma: 0.16.1
  • nexus: 0.26.0-next.3
  • prisma-upgrade: 0.0.34
  • prisma1: 1.34.11
  • ts-node-dev: 1.0.0-pre.50

TheoMer avatar Aug 03 '20 11:08 TheoMer