question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema must be an instance of GraphQLSchema

See original GitHub issue

Hello, I get this error when hitting /graphql with browser:

{
  "errors": [
    {
      "message": "Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
    }
  ]
}

any suggestion? My schema is an instance of GraphQLSchema…and graphql appears only once in package.json

thanks

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:29 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
helfercommented, Jun 15, 2016

@LoicMahieu: Unless you’re running a modified version of graphql-js, this shouldn’t be a problem if you npm dedupe. The limitation has to do with flow type checking.

4reactions
hallettjcommented, Jan 19, 2017

Just want to mention that when importing a schema from another package, and using yarn link in development, I run into the same problems that @LoicMahieu describes with lerna.

Edit: I found a solution, which I wanted to share in case anyone else runs into this issue: do more linking so that each of your packages is linked to the same copy of graphql. (This also works for other dependencies that are sensitive to multiple copies, such as react.)

In this scenario, schema-package exports a graphql schema, and server-package imports that schema, perhaps to serve it over HTTP:

  1. $ yarn global add graphql
  2. $ cd ~/.config/yarn/global/node_modules/graphql && yarn link
  3. $ cd path/to/schema-package && yarn link graphql && yarn link
  4. $ cd path/to/server-package && yarn link graphql && yarn link schema-package

After these steps, server-package is linked to your development copy of schema-package, and both are linked to the same copy of graphql. This should cause instanceof checks in graphql code to work properly.

@leebyron You said that the error has to do with flow type-checking; but I think that is not correct. The error comes from three runtime checks that look like this:

  invariant(
    schema instanceof GraphQLSchema,
    'Schema must be an instance of GraphQLSchema. Also ensure that there are ' +
    'not multiple versions of GraphQL installed in your node_modules directory.'
  );

Some options for avoiding errors like this when using lerna, yarn link, or npm link could be to change the check from an instanceof check to a check for expected properties, or to disable invariant checks if an environment variable or configuration option is set.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schema must be an instance of GraphQLSchema. Ensure that ...
js. fields is a function property. This works. let schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'RootQueryType', ...
Read more >
GraphQL schema basics - Apollo GraphQL Docs
Your GraphQL server uses a schema to describe the shape of your available data. This schema defines a hierarchy of types with fields...
Read more >
Building your first GraphQL Server | by christoffer noring
To create a schema you need to create an instance of the type GraphQLSchema . There are different ways of creating this instance...
Read more >
Constructing Types - GraphQL
When you are using the GraphQLSchema constructor to create a schema, instead of defining Query and Mutation types solely using schema language, you...
Read more >
Frequently Asked Questions - TypeGraphQL
and must perform side effects e.g. a database call - use a resolver class method ... In this case, what should be returned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found