Skip to content Skip to sidebar Skip to footer

Graphql Unknown Argument On Field

I am new to GraphQL. Whenever I try to send args on (posts) child node like the query below, I get an error msg 'Unknown argument id on field posts of type user'. I want to bring

Solution 1:

looks like you are missing args on users, hence, it should look like this:

var users  = new graphql.GraphQLObjectType({
  name : 'user',
  description : 'this is user info',
  fields : function(){
    return {
      id :{
        type : graphql.GraphQLInt,
        resolve(user){
          return user.id;
        }
      },
      username :{
        type : graphql.GraphQLString,
        resolve(user){
          return user.username;
        }
      },

      posts:{
        args: {
        id:{
            type : graphql.GraphQLInt,
        },
        type: new  graphql.GraphQLList(posts),
        resolve(user, args){
          // Code here to use args.idreturn user.getPosts();
        }
      }


    }
  }
});

Solution 2:

You this error if the argument does not exist in the field.

For example, in this case, invalidArg does not exist in the list. The only possible arguments are last, after, first, before, orderBy and ownedByViewer. If you try to pass anything else, you will get an error.

enter image description here

Solution 3:

Try replacing posts (plural) with post (singular).

post(id:2) {
          title
          tags {
            name
          }
        }

Post a Comment for "Graphql Unknown Argument On Field"