Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TheoMer opened this issue Aug 3, 2020 · 0 comments
Labels
type/bug Something is not working the way it should

Comments

@TheoMer
Copy link

TheoMer commented Aug 3, 2020

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 TheoMer added the type/bug Something is not working the way it should label Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is not working the way it should
Projects
None yet
Development

No branches or pull requests

1 participant