Ander
Ander

Reputation: 5634

How to create an array of arrays as input in ApolloGraphQL

How can I create an array of arrays as inputs in ApolloGraphQL?

For instance, how should be the Schema for a query like this:

{
    Users(Id:1, Filters:[["Id",">", "1"], ["Id","<","3"]]) {
      Id
      Name
    }
}

I have tried the following schema but no luck:

const typeDefs = gql`
  type Query{
      Users(
        Id: ID,
        Filters: [[String, String, String]]
      )
   }
 `;

What I am trying to achieve here is an Input type which is a List of Lists, with each of the child lists containing exactly 3 strings. So it can be called like this within the function: Filters:[["Id",">", "1"], ..]

Upvotes: 2

Views: 4491

Answers (2)

Ander
Ander

Reputation: 5634

Seems like it was easier than I though, would be enough using [[String]]:

const typeDefs = gql`
  type Query{
      Users(
        Id: ID,
        Filters: [[String]]
      )
   }
 `;

Upvotes: 1

Peter Schwarz
Peter Schwarz

Reputation: 301

Hi Ander I also tried to achieve something like that, but not luck either. I ended up using list of objects instead:

const typeDefs = gql`
  type Query{
      Users(
        Id: ID,
        Filters: [Filter]
      )
  }

  input Filter{
    A: String!
    B: String!
    C: String!
  }
`;

It will look like this at the end:

{
    Users(Id:1, Filters:[{A:"Id",B:">", C:"1"}, ..]) {
      Id
      Name
    }
}

Upvotes: 1

Related Questions