Passing an array as an argument in GraphQL

I started working on GraphQL . My schema also contains one list item.

Below is the code for my schema:

var userType = new graphql.GraphQLObjectType({  
 name: 'user',
 fields: function () {
  return {
    _id: {
    type: graphql.GraphQLID
  },
  name: {
    type: graphql.GraphQLString
  },
  age: {
    type: graphql.GraphQLString
  },
  degrees:[
  {type:graphql.GraphQLList}
  ]
}
  }
   });

And the request is as follows:

  var QueryType = new graphql.GraphQLObjectType({  
  name: 'Query',
  fields: () => ({
    userArr: {
      type: new graphql.GraphQLList(userType),
      args:{
         degrees:{type:new graphql.GraphQLList(userType)}
      },
     resolve: function(source, args) {
        console.log(args);
        resolve(args);
      }
    }
})
})

I got this error. enter image description here

Basically, I need to send an array from the graphql client request and determine the corresponding request that I cannot reach. Any suggestions because I cannot find any help on this issue.

+4
source share
2 answers

I recently did something very similar. Your input arguments , output . , , .

, () .

 var QueryType = new graphql.GraphQLObjectType({  
  name: 'Query',
  fields: () => ({
    userArr: {
      type: new graphql.GraphQLList(userType),
      args:{
         degrees:{type:new graphql.GraphQLList(graphql.GraphQLString)}
      },
     resolve: function(source, args) {
        console.log(args);
        resolve(args);
      }
    }
})
})

, , , . , . - :

  degrees:{
    type:new graphql.GraphQLList(graphql.GraphQLString)
  }

!

+2

GraphQLObjectType .

.

" , , , ".

, GraphQLString

degrees:{
    type:new graphql.GraphQLList(graphql.GraphQLString)
}

GraphQLInputObjectType

const userInputType = new GraphQLInputObjectType({
    name: 'userInput',
    fields: { /* put your fields here */ }
});
/* some code in between */

degrees:{
    type:new graphql.GraphQLList(userInputType)
}
0

Source: https://habr.com/ru/post/1660904/


All Articles