postgraphile-plugin-connection-filter-postgis
postgraphile-plugin-connection-filter-postgis copied to clipboard
Documentation missing
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).
I had same problem. Until I realized that you have to pass the geojson as object:
{
type: "Point",
coordinates: [14.996638298034668, 41.04304487986917],
}
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
So I agree: probably a single working example would help us a lot.
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 could you help here https://github.com/graphile-contrib/postgraphile-plugin-connection-filter-postgis/issues/15 ?
@andilabs sorry, I am struggling with this too
It can be written like this in GraphiQL