nexus icon indicating copy to clipboard operation
nexus copied to clipboard

Not defined in your GraphQL Schema, missing type: forgot to import a type to the root query

Open Slmii opened this issue 5 years ago • 2 comments

Often when I start up the dev server of nexus/schema "dev": "cross-env NODE_ENV=development ts-node-dev --no-notify --respawn --transpileOnly src/server",

I get these error messages: image

If I look at the first warning in schema.graphql it'll look like this:

type CustomerGroup {
  ...
  customerGroupDescription(cursor: CustomerGroupDescriptionWhereUniqueInput, orderBy: [CustomerGroupDescriptionOrderByInput!], skip: Int, take: Int, where: CustomerGroupDescriptionWhereInput): [CustomerGroupDescription!]!
  ...
}

and the type CustomerGroupDescription is also available in the schema.graphql

type CustomerGroupDescription {
  customerGroup: CustomerGroup!
  description: String
  id: Int!
  languageId: Int!
  name: String!
  uuid: String!
}

And this is the missing type error: - Missing type CustomerGroupDescriptionWhereInput, did you forget to import a type to the root query or mean... Which is also available in the schema.graphql

input CustomerGroupDescriptionWhereInput {
  AND: [CustomerGroupDescriptionWhereInput!]
  customerGroup: CustomerGroupWhereInput
  customerGroupId: IntFilter
  description: NullableStringFilter
  id: IntFilter
  languageId: IntFilter
  name: StringFilter
  NOT: [CustomerGroupDescriptionWhereInput!]
  OR: [CustomerGroupDescriptionWhereInput!]
  uuid: UUIDFilter
}

When I save a file once or twice and after the server has restarted the errors go away and everything works fine. Also strange is the warning always differ, its never the same type/inputs.

Slmii avatar Sep 01 '20 11:09 Slmii

I experienced this when cloning https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql-auth and refactoring Post, post, Posts & posts to a more appropriate to my usecase model Session, sessions […]. However this error appeared when I forgot to also rename /src/types/Post.ts to /src/types/Session.ts

chris-aeviator avatar Oct 03 '20 10:10 chris-aeviator

I'm assuming for custom scalar types such as t.date or t.json to work, we need to invoke asNexusMethod and pass them to makeSchema under type to make them available... however, right now I'm seeing (or suspecting), in order to use t.date, we need to generate the types first (as in, invoke makeSchema({type: [dateScalar, jsonScalar]}) before they are available), and then we can safely use them.

A problem I'm seeing is, if I have a fresh project (without the custom scalar types), and I try to invoke makeSchema({type: [dateScalar, jsonScalar, myOwnTypes]}), typescript actually complains that t.date and t.json are not valid.

This makes sense because without invoking makeSchema, there's no way to know that they are available. However, this is massively annoying, because the work around is that I have comment out myOwnTypes, invoke makeSchema with the custom scalars, and then uncomment again.

Is this happening to anyone?

Following are the node_modules

"apollo-server-fastify": "^3.1.2",
"graphql": "^15.5.1",
"graphql-middleware": "^6.0.10",
"graphql-scalars": "^1.10.0",
"nexus": "^1.1.0",

bbbryan14 avatar Aug 18 '21 19:08 bbbryan14