【发布时间】:2017-12-03 03:26:52
【问题描述】:
如何在 nodeJS 中实现具有可选参数的 GraphQL Mutation?
我当前的突变有一个 args 字段,但所有参数都是强制性的。由于我在文档中找不到任何内容,因此我不知道如何或是否可能。
这是我当前的代码:
const fakeDB = {
count: 0
};
const schema = new GraphQLSchema({
query: //...
mutation: new GraphQLObjectType({
name: 'adsF',
fields: {
updateCount: {
type: GraphQLInt,
args: {
count: { type: GraphQLInt } // I want to make this argument optional
},
resolve: (value, { count }) => {
// Catch if count is null or undefined
if (count == null) {
// If so just update with default
fakeDB.count = 5;
} else {
fakeDB.count = count
}
return fakeDB.count;
})
}
}
})
});
感谢您的帮助!
【问题讨论】:
标签: javascript node.js graphql-js