This is a PostGraphile schema
plugin that provides
support for the popular PostGIS spatial database
system.
Create a PostgreSQL database with PostGIS
columns, run PostGraphile with this
plugin, and have a fully functional geospatial-aware
GraphQL API for your database.
Work is ongoing, here’s the plan:
geojsonlongitude and latitude on geography(POINT)geometries in a longitude and latitude) ongeography(LINESTRING) and geography(POLYGON)geography(POINT)geography(LINESTRING) and geography(POLYGON)postgraphile-plugin-connection-filter to enable PostGIS specific filtering (via postgraphile-plugin-connection-filter-postgisgeography(LINESTRING) and geography(POLYGON), such as area,length, perimeter, and centroidThere are many, many other features that this plugin could support - if you
have specific needs please get in touch!
This plugin requires PostGraphile v4.4.0 or higher to function correctly.
Add PostGIS to your database:
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
Load the plugin:
postgraphile --append-plugins @graphile/postgis
Using this table as example:
CREATE TABLE data (
id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc(),
geom_point geometry(Point, 4326) default null
);
In queries geom_point is represented as type GeometryPoint. Example:
query {
allDatas {
nodes {
geomPoint {
geojson
srid
x
y
}
}
}
}
In mutations geom_point is represented as type GeoJSON. Example:
mutation ($id: UUID!, $geomPoint: GeoJSON!) {
updateDataById(
input: {
id: $id,
dataPatch: {
geomPoint: $geomPoint
}
}
) { ... }
}
with these variables:
{
"id": "0116254a-0146-11ea-8418-4f89d6596247",
"geomPoint": {
"type": "Point",
"coordinates": [8.5, 47.5]
}
}
Beware of the fact that since 2016 the GeoJSON spec expects the coordinates to be of SRID 4326/WGS84 (see https://tools.ietf.org/html/rfc7946#section-4). So adding a crs field to the GeoJSON is deprecated. Thus since v3 PostGIS will be happy to receive above GeoJSON.
undefinedIn earlier versions PostGIS expects a SRID to be passed. So the variables would be:
{
"id": "0116254a-0146-11ea-8418-4f89d6596247",
"geomPoint": {
"type": "Point",
"coordinates": [8.5, 47.5],
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
}
}
}
Contributions are extremely welcome! To get started, clone down this repo and then:
createdb graphile_test
export TEST_DATABASE_URL=postgres://localhost:5432/graphile_test
yarn
yarn dev
Note the development server runs at http://localhost:5123/graphiql
To run the tests:
yarn test
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.