2017-03-19 27 views
2

我有以下模式:模式沒有配置的突變

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})); 

什麼是缺失的事情,使突變配置?

回答

2

我得到了我的錯誤,這是一個錯字:而不是在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 
     } 
    }) 
    }) 
}) 
+0

我有'突變'>。> lol – afreeland