-
-
Notifications
You must be signed in to change notification settings - Fork 122
Description
Summary
The postgres postgis extension introduces geometry and geography column types with large set of new query operators. Generally, these column types serialize and deserialize successfully into geojson as per my experimental branch here, where I was exploring the use of postgis in conjunction with pg_graphql. To truly make these column types useful with pg_graphql, however, the various query operators capable of filtering rows based on geometry or geography must be introduced into the available pg_graphql filter types.
Rationale
Without additional filter support for geometry and geography types, pg_graphql is only minimally useful for any database that needs to store geographic or geometric information.
Design
I believe one of two design approaches would suffice to introduce better filters for postgis.
- Allow pg_graphql app developers to introduce their own filter types somehow, via some combination of plpgsql functions, postgres types, and / or postgres domains. This would solve the filtering problem for the postgis extension, and also allow app developers to introduce their own custom filters for column types like
jsonandjsonb. - Add direct support for the postgis extension, and the included
geographyandgeometrytypes to pg_graphql. This would allow other pg_graphql app developers to activate the postgis extension with minimal effort.
Examples
Postgis supports all of the following sql operators: https://postgis.net/docs/manual-1.5/ch08.html
For filtering, I have found the most common operators to be (from geoalchemy2):
INTERSECTS ("&&")
INTERSECTS_ND ("&&&")
OVERLAPS_OR_TO_LEFT ("&<")
OVERLAPS_OR_TO_RIGHT ("&>")
OVERLAPS_OR_BELOW ("&<|")
TO_LEFT ("<<")
BELOW ("<<|")
TO_RIGHT (">>")
CONTAINED ("@")
OVERLAPS_OR_ABOVE ("|&>")
ABOVE ("|>>")
CONTAINS ("~")
SAME ("~=")
DISTANCE_CENTROID ("<->")
DISTANCE_BOX ("<#>")
Where the item on either side of the comparator can be a geometry, geography, or text value that casts to geometry. (One side being the column of the table being filtered, and the other side being the value passed into graphql as the filter value)
Drawbacks
Unknown.
Alternatives
None available.
Unresolved Questions
TBD.