Nic*_*mid 2 javascript node.js graphql-js
我将如何在具有可选参数的 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;
})
}
}
})
});
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
| 归档时间: |
|
| 查看次数: |
9617 次 |
| 最近记录: |