如何在nodeJS中实现具有可选参数的GraphQL突变?
我当前的突变有一个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;
})
}
}
})
});谢谢你的帮忙!
发布于 2017-07-07 16:31:32
默认情况下,GraphQL中的类型可以为空。这意味着您目前指定突变的方式使计数成为可选的。如果希望某个字段为必填字段,则需要将其标记为non null
https://stackoverflow.com/questions/44824942
复制相似问题