[英]GraphQL-js mutation optional arguments
how would I achieve a GraphQL Mutation in nodeJS that has arguments which are optional? 如何在具有可选参数的nodeJS中实现GraphQL突变?
My current mutation has an args field, but all the arguments are mandatory. 我当前的变异有一个args字段,但是所有参数都是必需的。 Since I couldn't find anything in the documentation, I don't know how or if this is possible. 由于我在文档中找不到任何内容,因此我不知道如何或是否可行。
This is my current code: 这是我当前的代码:
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;
})
}
}
})
});
Thanks for Your help! 谢谢你的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.