Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation missing #10

Open
lamuertepeluda opened this issue Nov 25, 2019 · 7 comments
Open

Documentation missing #10

lamuertepeluda opened this issue Nov 25, 2019 · 7 comments

Comments

@lamuertepeluda
Copy link

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).

@barbalex
Copy link

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

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

@barbalex
Copy link

barbalex commented Apr 30, 2020

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
Copy link

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

@barbalex
Copy link

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?

@andilabs
Copy link

@barbalex could you help here #15 ?

@barbalex
Copy link

@andilabs sorry, I am struggling with this too

@gqians
Copy link

gqians commented Sep 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants