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;
})
}
}
})
});
感謝您的幫助!
哦,謝謝!我沒有意識到這一點! –