2

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"], ..]

3
  • any knowledge about query variables and input types ? graphql.org/learn/schema/#input-types Commented May 27, 2020 at 12:10
  • 1
    Thanks for your link, says nothing about how to create a list of lists as inputs but I appreciate it. Commented May 28, 2020 at 11:35
  • update question with types you tried to define Commented May 28, 2020 at 11:38

2 Answers 2

1

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
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Peter Its a good alternative, but I find it a bit verbose. I'll keep trying..
1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.