postgraphile-plugin-connection-filter-postgis icon indicating copy to clipboard operation
postgraphile-plugin-connection-filter-postgis copied to clipboard

Documentation missing

Open lamuertepeluda opened this issue 6 years ago • 7 comments

The documentation on how to use filters is unclear/missing. I think you should provide at least 1 example.

I tried to filter by a point on the following table containing polygons of several countries, guessing from several issues of the posgraphile ecosystem.

CREATE TABLE public.countries (
	ogc_fid serial NOT NULL,
	id varchar NULL,
	"name" varchar NULL,
	wkb_geometry geometry NULL,
	CONSTRAINT countries_pkey PRIMARY KEY (ogc_fid)
);
{
  allCountries(filter: {wkbGeometry: {containsProperly: "{\"type\":\"Point\",\"coordinates\":[14.996638298034668,41.04304487986917]}"}}) {
    nodes {
      wkbGeometry {
        geojson
      }
    }
  }
}

I always get:

{
  "errors": [
    {
      "message": "unknown GeoJSON type",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "allCountries"
      ]
    }
  ],
  "data": {
    "allCountries": null
  }
}

No matter how I pass the point (wkt, json, full point feature...). Is it me passing the wrong argument? Is some weird parsing/escaping (I would suggest to also support WKT/EWKT).

lamuertepeluda avatar Nov 25 '19 16:11 lamuertepeluda

I had same problem. Until I realized that you have to pass the geojson as object:

{
  type: "Point",
  coordinates: [14.996638298034668, 41.04304487986917],
}

barbalex avatar Apr 30 '20 13:04 barbalex

Passing in

{
  type: "Point",
  coordinates: [14.996638298034668, 41.04304487986917],
}

directly in graphiql is o.k.

My problem is: How do I pass it in as variable?

This is my query:

result = await client.query({
  query: gql`
    query tpopGemeindeQuery($point: GeoJSON) {
      allChGemeindes(
        filter: {
          wkbGeometry: { containsProperly: $point }
        }
      ) {
        nodes {
          name
        }
      }
    }
  `,
  variables: {
    point: pointCorrectlyFormatted?,
  },
})

It seems that the variable has to be:

{"point": {"type":"Point","coordinates":[8.529259225,47.549318163]}}

because this works in graphiql. Even though gaphiql's linter complains: "expected value of type GeoJSON".

But how do I convert a queried geojson output:

"{"type":"Point","coordinates":[8.496577597,47.311831695]}"

to

{"point": {"type":"Point","coordinates":[8.529259225,47.549318163]}}

?

I think it is not possible as

{"point": {"type":"Point","coordinates":[8.529259225,47.549318163]}}

only works in graphiql, not in JavaScript.

Any way I try I only get this error: unknown GeoJSON type

barbalex avatar Apr 30 '20 14:04 barbalex

So I agree: probably a single working example would help us a lot.

barbalex avatar Apr 30 '20 15:04 barbalex

I found a very hacky solution:

result = await client.query({
  query: gql`
    query tpopGemeindeQuery {
      allChGemeindes(
        filter: {
          wkbGeometry: { containsProperly: {type: "${geojsonParsed.type}", coordinates: [${geojsonParsed.coordinates}]} }
        }
      ) {
        nodes {
          name
        }
      }
    }
  `,
})

Not very happy with this. Is there a better way?

barbalex avatar Apr 30 '20 15:04 barbalex

@barbalex could you help here https://github.com/graphile-contrib/postgraphile-plugin-connection-filter-postgis/issues/15 ?

andilabs avatar Jul 21 '20 09:07 andilabs

@andilabs sorry, I am struggling with this too

barbalex avatar Jul 21 '20 19:07 barbalex

2020-09-15 11-25-55 的屏幕截图 It can be written like this in GraphiQL

gqians avatar Sep 15 '20 03:09 gqians