GraphQL-js mutation optional arguments

Viewed 12448

how would I achieve a GraphQL Mutation in nodeJS that has arguments which are optional?

My current mutation has an args field, but all the arguments are mandatory. 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!

1 Answers
Related