-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Schema must be an instance of GraphQLSchema #58
Comments
Ok, it's related to babel 6 (babel-core). If I use [email protected] then no problem. Maybe there is a babel 6 preset that could work, I just tried with |
I'm not able to reproduce this. Please let me know if you stumble upon a clearer reason for the issue so I can help fix. |
I think I'm running into the same issue. I tried to use [email protected] but with no success here is my project : https://github.com/muskacirca/graphqlserver If anyone have an idea on what is going on, it will be great. |
Sometimes this occurs if you have multiple copies of graphql-js in your node_modules folder, that can happen if different parts of your app require different versions of the library. |
A good way to diagnose this is to run |
Actually I was getting the first error : Schema must be an instance of GraphQLSchema It was an error in how I export & import my schema. export var Schema = new GraphQLSchema({ import {Schema} from './schema' --> adding the brackets solve my issue |
@leebyron I am getting this exact error message with multiple copies of the same version of graphql in node_modules. Running npm shrinkwrap all entries ae like this: graphql: '^0.4.18' I have two modules, both depend on graphql and one depends on the other. Is this unsupported, or could you give any pointers to what I could try? ps. this is not related to graphiql i think, but posting here as this is the only mention i have seen of this. |
Unfortunately there's no work around for this at the moment. The solution is to ensure that there is exactly one copy of graphql-js in your node_modules (recursively). The latest versions of npm (v3) should install maximally flat, so if you have multiple dependencies that require graphql, it should just be a matter of ensuring that they depend on the same version of graphql-js |
Thanks Lee! |
Is there any reason about the necessary to share the same graphql-js module ? I wanted to split my code in multiple modules, one module for graphql defintions and one other module for serving it with express-graphql. Unfortunatly, due to this limitation, this is not possible. |
@LoicMahieu: Unless you're running a modified version of graphql-js, this shouldn't be a problem if you |
@helfer In my case the problem is not the version. We use have several packages in the same repository and we use |
I haven't used |
To be clear: it's certainly possible to split up your graphql definitions into multiple packages, and it's a pattern I see very often in larger codebases. The critical detail is that the package.json for each must refer to the same version of |
I have the same issue. EDIT: Have only tested with |
Have you checked the way you import yoiur schema ?
|
@muskacirca: Yes, but I'm using a type definition array. According to the docs this should work as well. Here my setup: schema.js: const typeDefinitions = `
type Person {
id: Int!
}
# this schema allows the following two queries:
type RootQuery {
person(id: Int): Person
}
type RootMutation {
createPerson(
name: String!
): Person
}
schema {
query: RootQuery
mutation: RootMutation
}
`;
export default [typeDefinitions]; server.js import koa from 'koa';
import koaRouter from 'koa-router'
import { apolloKoa, graphiqlKoa } from 'apollo-server';
import schema from './graphql/schemas';
import mocks from '../data/mock';
const app = new koa();
const router = new koaRouter();
router.get('/graphiql', graphiqlKoa({
endpointURL: '/graphql'
}));
router.post('/graphql', apolloKoa({
schema,
mocks,
printErrors: true
}));
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000, () =>
console.log('GraphQL running on 3000')); // eslint-disable-line no-console |
Find the culprit: Seems like the documentation isn't fully updated yet to reflect the recent changes in |
Glad you figured it out |
Still having this problem. All recursive dependencies have the same version:
|
I think this is the solution (if you're using webpack): |
Just want to mention that when importing a schema from another package, and using 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,
After these steps, @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.'
);
|
In case this helps anyone else, I've came across this when mixing ES6 and CommonJS modules. Choosing one or the other sorted it. |
@davidMuir I was afraid of this =( I am using |
If you're using |
In case it helps anyone else, I got this error when |
In my case, the issue was not having twice
I found that by inspecting |
Had the same issue and turned out I have both |
@richburdon's solution worked for me. In webpack config: resolve: {
alias: {
graphql: path.resolve('./node_modules/graphql')
}
} |
…ransform-class-properties-6.19.0 Update babel-plugin-transform-class-properties to the latest version 🚀
* bump: version for 0.0.10 * feat: codelens without query * feat: inline playground and codelens * feat: codelens, extract graphql response from apollo response * feat: codelens, ignore template variables for now * fix: regex * bump version for release * fix: configuration, update deps * fix: deps * fix: add codelens only for executable operations * bump version * fix: support scalars, code clean up * fix: codelens, add support for object type * fix: codegen, handle lists as input * fix: codelens, constructor * bump version for internal release * dep: add subscriptions-transport-ws * fix: add catch brackets * fix: added parameter to constructor * chore: add fish shell support * chore: bump version * fix: race condition between input and content provider * bump version * beta: mark as preview * bump version
Hello,
I get this error when hitting /graphql with browser:
any suggestion? My schema is an instance of GraphQLSchema...and graphql appears only once in
package.json
thanks
The text was updated successfully, but these errors were encountered: