0

I have a working query which looks like this:

query orgs($limit: Int = 10) {
  orgs: research_db_fundingorganization(limit: $limit) {
    gridreference {
      id: data(path: "id")
      name: data(path: "name")
      country: data(path: "addresses[0].country")
      city: data(path: "addresses[0].city")
      types: data(path: "types")
    }
  }
}

but I only want to return objects if say orgs.gridreference.country is equal to Austria.

I can't work out how to filter on a value that might exist deeper on a path.

Filtering orgs.gridreference.id and orgs.gridreference.name are simple and can be done like this:

query orgs($limit: Int = 10, $query: jsonb = {id: "grid.458347.9"}) {
  orgs: research_db_fundingorganization(limit: $limit, where: {gridreference: {data: {_contains: $query}}}) {
    gridreference {
      id: data(path: "id")
      name: data(path: "name")
      country: data(path: "addresses[0].country")
      city: data(path: "addresses[0].city")
      types: data(path: "types")
    }
  }
}

FYI, the above produces the result:

{
  "data": {
    "orgs": [
      {
        "gridreference": {
          "id": "grid.458347.9",
          "name": "Austrian Development Agency",
          "country": "Austria",
          "city": "Vienna",
          "types": [
            "Government"
          ]
        }
      }
    ]
  }
}

Why is it not possible to do something like this:

query orgs($limit: Int = 10, $grid_country: String = "Austria") {
  orgs: research_db_fundingorganization(limit: $limit, where: {gridreference: {country: {_eq: $grid_country}}}) {
    gridreference {
      id: data(path: "id")
      name: data(path: "name")
      country: data(path: "addresses[0].country")
      city: data(path: "addresses[0].city")
      types: data(path: "types")
    }
  }
}
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
dnk8n
  • 675
  • 8
  • 21
  • GraphQL has no built-in way of doing filtering. This question is specific to whatever particular service you are querying. There is no way to answer it without knowing the server's schema. – Daniel Rearden Jul 17 '20 at 11:21
  • Aah right. So I am using Hasura. It is a public API I set up. Could link it here I guess because it is public. – dnk8n Jul 18 '20 at 21:11
  • What I know I can do is, instead of returning a jsonb schema-less blob for one of the fields, I can set up relationships in the Postgres database and in that way the GraphQL data will be more structured. – dnk8n Jul 18 '20 at 21:15

0 Answers0