P
P
PeroPero2018-06-22 19:31:14
JavaScript
PeroPero, 2018-06-22 19:31:14

How to pass an array of objects as GraphQL query arguments?

There is a good example in the help.

var schema = buildSchema(`
  type ouTest{
    num: Int
    qwe: Int
  }

  input inTest{
    num: Int
    qwe: Int
  }
  type Query {
    rollDice(input: [inTest]): [ouTest]
  }
`);

I can't figure out how to rewrite it to this
const imgS = new graphql.GraphQLObjectType({
  name: "img",
  fields: () => {
    return {
      a: {type: graphql.GraphQLInt},
      b: {type: graphql.GraphQLInt}
    }
  }
})

const img = {
  type: new graphql.GraphQLList(imgS),
  args: {
    input: [imgS] // Как тут прописать input массив объектов 
  },
  resolve (source, args, context) {
    return args; 
  }
}

const Query = new graphql.GraphQLObjectType({
  name: 'Query',
  description: 'Root query object',
  fields: () => {
    return {
      img: img
    };
  }
})

var schema = new graphql.GraphQLSchema({
  query: Query
});

As a result, I want to see the request
{
   returnUserN(img: [{a: 123, b:456}]){
     a
     b
  }
}

I tried different options, but it did not work out as an argument to pass an array of objects.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PeroPero, 2018-06-23
@PeroPero

Solution found

args: {
   id: {type: new graphql.GraphQLList(img1)}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question