0

Is it possible to have a JSON object as filed in filter arguments. Something like:

    Query{
      building(location:{lon,lat}){
        name,...
      }
    }

I need to pass location, and I would like to pass it as js object ( to apollo client) or as stringified JSON.

klo
  • 414
  • 2
  • 6
  • 14
  • 2
    Possible duplicate of [GraphQL.js Node/Express: How to pass object as GraphQL query argument](https://stackoverflow.com/questions/42722888/graphql-js-node-express-how-to-pass-object-as-graphql-query-argument) – Daniel Rearden Dec 20 '18 at 15:09
  • 1
    See also [here](https://stackoverflow.com/questions/39759988/apollo-graphql-mutation-object-argument) and [here](https://stackoverflow.com/questions/39114417/graphql-args-error-argument-type-must-be-input-type-but-got-function-graphqlob) – Daniel Rearden Dec 20 '18 at 15:13

1 Answers1

2

You can use input types to achieve that. You need to edit your schema

type Query {
    building(location: Location): Building
}

input Location {
    lon: String
    lat: String
}

Then you can post your query like this

query {
  building(location: {lon:"100.332680",lat:"5.416393"}) {
    name,...
  }
}
xwlee
  • 1,083
  • 1
  • 11
  • 29