1
votes

I defined the below query in my GraphQL schema

type Query {        
    getShowByName(showSchemaName: String!): String!        
}

with the corresponding resolver function as shown below

const resolvers = ()=>({
    Query:{

        getShowByName: function(args){
            console.log("out1"+args);
            console.log("out3"+args.showSchemaName);            
            return "hardcoded return from getShowByName";           
        },        
    },    
});

In the graphql playground, i provided the below inputs

{
  getShowByName(showSchemaName:"input to getShowByName")  
}

The graphql playground provides hardcoded return from getShowByName as output in the playground page but in the terminal i get args as undefined. Hence, i am unable to parse the input fed in from the graphql playground.

Please help me in understanding where i am going wrong and how i can rectify the issue.

1

1 Answers

2
votes

The first argument in the resolver is an object that contains the result of parent resolver. In your case, the root level Query will receive undefined. Instead you should extract the args from the second argument.

const resolvers = ()=> ({
    Query: {
        getShowByName: function(_, args) {
            console.log("out1" + args);
            console.log("out3" + args.showSchemaName);            
            return "hardcoded return from getShowByName";           
        },        
    },    
});