hasura/graphql-engine

docs: document support for st_within or st_dwithin for polygons

Open

#3,015 opened on Oct 4, 2019

View on GitHub
 (3 comments) (0 reactions) (0 assignees)TypeScript (31,371 stars) (2,787 forks)batch import
a/data/postgresc/docshelp wanted

Description

I need to get the following query in PostgreSQL

SELECT count(*) 
FROM geo_locations
WHERE ST_DWithin(coordinates, 'POLYGON((58.44773280389084 -19.335937500000004, 56.17002298293205 -14.765625000000002, 55.7765730186677 4.218750000000001, 54.36775852406841 9.492187500000002, 52.26815737376817 9.843750000000002, 45.089035564831036 3.5156250000000004, 42.293564192170095 8.085937500000002, 40.979898069620155 7.382812500000001, 41.244772343082076 3.5156250000000004, 52.482780222078226 -14.765625000000002, 57.89149735271034 -20.390625000000004, 60.75915950226991 -21.796875000000004, 58.44773280389084 -19.335937500000004))', 100)

or

SELECT count(*) 
FROM geo_locations
WHERE ST_DWithin(coordinates, ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[58.44773280389084,-19.335937500000004],[56.17002298293205,-14.765625000000002],[55.7765730186677,4.218750000000001],[54.36775852406841,9.492187500000002],[52.26815737376817,9.843750000000002],[45.089035564831036,3.5156250000000004],[42.293564192170095,8.085937500000002],[40.979898069620155,7.382812500000001],[41.244772343082076,3.5156250000000004],[52.482780222078226,-14.765625000000002],[57.89149735271034,-20.390625000000004],[60.75915950226991,-21.796875000000004],[58.44773280389084,-19.335937500000004]]]}'), 100)

I'm trying to do it with

query ($polygon: st_d_within_input) {
  geo_locations(where: {coordinates: {_cast: {geometry: {_st_d_within: $polygon}}}}) {
    search_key
  }
}

but it fails with

{
  "errors": [
    {
      "extensions": {
        "path": "$.variableValues.polygon",
        "code": "validation-failed"
      },
      "message": "field distance of type Float! is required, but not found"
    }
  ]
}

Contributor guide

docs: document support for st_within or st_dwithin for polygons · hasura/graphql-engine#3015 | Good First Issue