Is it possible to pass an object into a graphQL query/mutation as variables?

Is it possible to pass an object into a graphQL query/mutation as variables? I don’t see any way to define an object as a parameter type.

1 Like

A little late perhaps, but I think it can be helpful for reference for some people to reply anyway. I found my answer on the github linked below.

schema

input Filter {
  term: String
}

type Record {
  name: String
}

type Query {
  find(filter: Filter!, count: Int!): [Record]
}

resolver

Query: {
  async find(root, { filter, count }) {
    // do your work with filter.term
  }
}

graphiql query

{
  find(filter: { term: "foo" }, count: 5) {
    name
  }
}

This is where the info is comming from:

https://github.com/graphql/graphql-js/blob/a68212eeffb1fae8e5783f461508d82c01e7a686/src/language/tests/schema-kitchen-sink.graphql

2 Likes