Abd*_*UMI 4 node.js graphql graphql-js
我有以下架构:
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLInt,
GraphQLString
} from 'graphql';
let counter = 100;
const schema = new GraphQLSchema({
// Browse: http://localhost:3000/graphql?query={counter,message}
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
counter: {
type: GraphQLInt,
resolve: () => counter
},
message: {
type: GraphQLString,
resolve: () => 'Salem'
}
})
}),
mutiation: new GraphQLObjectType({
name: 'Mutation',
fields: () => ({
incrementCounter: {
type: GraphQLInt,
resolve: () => ++counter
}
})
})
})
export default schema;
Run Code Online (Sandbox Code Playgroud)
以下查询工作正常:
{counter, message}
Run Code Online (Sandbox Code Playgroud)
但是,mutation {incrementCounter}引发以下错误:
{
"data": null,
"errors": [
{
"message": "Schema is not configured for mutations",
"locations": [
{
"line": 1,
"column": 1
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
已知服务器是:
import GraphQLHTTP from 'express-graphql';
const app = express();
app.use('/graphql',GraphQLHTTP({schema}));
Run Code Online (Sandbox Code Playgroud)
突变配置的缺失之处是什么?
我遇到了错误,这是一个错字:mutation我写的不是在Schema构造函数中写的mutiation。
const schema = new GraphQLSchema({
// Browse: http://localhost:3000/graphql?query={counter,message}
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
counter: {
type: GraphQLInt,
resolve: () => counter
},
message: {
type: GraphQLString,
resolve: () => 'Salem'
}
})
}),
mutation: new GraphQLObjectType({ //?? NOT mutiation
name: 'Mutation',
fields: () => ({
incrementCounter: {
type: GraphQLInt,
resolve: () => ++counter
}
})
})
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3934 次 |
| 最近记录: |