Graphql arguments returns {} when using variables

17 views Asked by At

I just want to test my query mutation with Postman. Here is my query

mutation ($input: registerSupplierInput){
        registerSupplier(input: $input){
          message
          success
        }
}

And variables:

{"email":"[email protected]", "name":"1", "address":"1", "location":[36.24,44.04], "phone_numbers":["1"]}

And here is my server schema types:

const registerSupplierInput = new GraphQLInputObjectType({
    name: 'registerSupplierInput',
    fields: {
        name: {type: new GraphQLNonNull(GraphQLString)},
        email: {type: new GraphQLNonNull(GraphQLString)},
        address: {type: new GraphQLNonNull(GraphQLString)},
        location: {type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLFloat)))},
        phone_numbers: {type: new GraphQLList(new GraphQLNonNull(GraphQLString))},
    }
});

const registerSupplierResponse = new GraphQLObjectType({
    name: 'registerSupplierType',
    fields: {
        success: {type: new GraphQLNonNull(GraphQLBoolean)},
        message: {type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString)))},
    }
});


module.exports.registerSupplier = {
    type: new GraphQLNonNull(registerSupplierResponse),
    args: {
        input: {type: registerSupplierInput}
    },
    async resolve(_, args){
        try {
            console.log(_, args);
            const {registerSupplier} = require('../controllers/supplier');
            return await registerSupplier(args);
        }
        catch(error){
            return error;
        }
    }
}

When i request a query the args parameter returns {} in the server log. What's wrong with my code?

0

There are 0 answers