graphiql: Schema must be an instance of GraphQLSchema

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

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 29 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@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.

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.

In my case, the issue was not having twice graphql but twice @types/graphql. Downgrading my apollo-client version from ^1.9.1 to 1.9.0 solved it :

$ yarn add apollo-client@1.9.0

I found that by inspecting yarn.lock file, and identifying which dependency was requiring a different version of @types/graphql.

In case this helps anyone else, I’ve came across this when mixing ES6 and CommonJS modules. Choosing one or the other sorted it.

Find the culprit: Seems like the documentation isn’t fully updated yet to reflect the recent changes in v0.2. The solution is to follow the upgrade guide which contains more information then the server setup doc.

Ok, it’s related to babel 6 (babel-core). If I use babel@5.8.34 then no problem. Maybe there is a babel 6 preset that could work, I just tried with presets: ['es2015', 'stage-1', 'react'] and with presets: ['es2015'], both without success (https://github.com/graphql/graphql-js/issues/228)

In case it helps anyone else, I got this error when graphql was installed as a devDependency instead of a normal dependency with the rest of my graphql-related packages.