1
如何在nodeJS中实现具有可选参数的GraphQL突变?GraphQL-js突变可选参数
我目前的突变有一个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;
})
}
}
})
});
感谢您的帮助!
哦,谢谢!我没有意识到这一点! –