【问题标题】:Schema is not configured for mutations没有为突变配置架构
【发布时间】:2017-08-10 12:02:51
【问题描述】:

我有以下架构:

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;

以下查询工作正常:

{counter, message}

但是,mutation {incrementCounter} 抛出以下错误:

{
  "data": null,
  "errors": [
    {
      "message": "Schema is not configured for mutations",
      "locations": [
        {
          "line": 1,
          "column": 1
        }
      ]
    }
  ]
}

知道服务器是:

import GraphQLHTTP from 'express-graphql';
const app = express();
app.use('/graphql',GraphQLHTTP({schema}));

配置突变的缺失是什么?

【问题讨论】:

    标签: node.js graphql graphql-js


    【解决方案1】:

    我收到了错误,这是一个错字:我没有在 Schema 构造函数中写 mutation,而是写了 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
          }
        })
      })
    })
    

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 1970-01-01
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2017-01-06
      • 1970-01-01
      • 2019-12-21
      相关资源
      最近更新 更多