gpt4 book ai didi

node.js - 架构未配置为突变

转载 作者:搜寻专家 更新时间:2023-10-31 23:45:59 24 4
gpt4 key购买 nike

我有以下架构:

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

配置突变的缺失是什么?

最佳答案

我得到了错误,这是一个拼写错误:我没有在 Schema 构造函数中编写 mutation,而是编写了 mutation

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

关于node.js - 架构未配置为突变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42882777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com