架构必须是 GraphQLSchema 的一个实例。确保 node_modules 目录中没有安装多个版本的 GraphQL
Schema must be an instance of GraphQLSchema. Ensure that there are not multiple versions of GraphQL installed in your node_modules directory
我在 graphiql 中有错误
"message": "Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
我试过了find node_modules -name graphql
。但是我只有一个版本的 graphql。
schema.js
import {
GraphQLObjectType,
GraphQLSchema,
GraphQLInt
} from 'graphql';
let count = 0;
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: GraphQLInt,
resolve: function() {
return count;
}
}
}
})
});
export default schema;
package.json
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"express": "^4.16.2",
"express-graphql": "^0.6.11",
"graphql": "^0.11.7",
"mysql": "^2.15.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-relay": "^1.4.1",
"require-clean": "^0.1.3",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.5"
}
server.js
import express from 'express';
import graphQLHTTP from 'express-graphql';
var Schema = require('./data/schema');
const GRAPHQL_PORT = 8080;
let graphQLServer;
const graphQLApp = express();
graphQLApp.use('/', graphQLHTTP({
graphiql: true,
pretty: true,
schema: Schema,
}));
graphQLServer = graphQLApp.listen(GRAPHQL_PORT, () => {
console.log(
GraphQL server is now running.
);
});
服务器运行良好而且我可以在控制台中获取 GraphQL 服务器 运行。但是 graphiql 显示错误。
知道其中有什么问题吗?
schema.js 中存在语法错误。 fields
是函数 属性。这行得通。
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: ()=> ({
count: {
type: GraphQLInt,
resolve:()=> {
return count;
}
}
})
})
});
server.js
import Schema from './data/schema';
我在 graphiql 中有错误
"message": "Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory."
我试过了find node_modules -name graphql
。但是我只有一个版本的 graphql。
schema.js
import {
GraphQLObjectType,
GraphQLSchema,
GraphQLInt
} from 'graphql';
let count = 0;
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: {
count: {
type: GraphQLInt,
resolve: function() {
return count;
}
}
}
})
});
export default schema;
package.json
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1",
"express": "^4.16.2",
"express-graphql": "^0.6.11",
"graphql": "^0.11.7",
"mysql": "^2.15.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-relay": "^1.4.1",
"require-clean": "^0.1.3",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.5"
}
server.js
import express from 'express';
import graphQLHTTP from 'express-graphql';
var Schema = require('./data/schema');
const GRAPHQL_PORT = 8080;
let graphQLServer;
const graphQLApp = express();
graphQLApp.use('/', graphQLHTTP({
graphiql: true,
pretty: true,
schema: Schema,
}));
graphQLServer = graphQLApp.listen(GRAPHQL_PORT, () => {
console.log(
GraphQL server is now running.
);
});
服务器运行良好而且我可以在控制台中获取 GraphQL 服务器 运行。但是 graphiql 显示错误。
知道其中有什么问题吗?
schema.js 中存在语法错误。 fields
是函数 属性。这行得通。
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: ()=> ({
count: {
type: GraphQLInt,
resolve:()=> {
return count;
}
}
})
})
});
server.js
import Schema from './data/schema';