npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@graphile/postgis

v0.2.0

Published

PostGIS support for PostGraphile

Downloads

6,867

Readme

@graphile/postgis

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.

Roadmap

Work is ongoing, here's the plan:

  • [x] Read-only support for geojson field from all geography types (via a shared GraphQL interface)
  • [x] Add GraphQL types for all the expected geography types (implementing this interface)
  • [x] Read-only support for determining the geometry sub-types of columns and exposing these directly (rather than the interface)
  • [x] Read-only support for longitude and latitude on geography(POINT) columns
  • [x] Read-only support for viewing the list of geometries in a geography(GEOMETRYCOLLECTION)
  • [x] Read-only support for a list of points (longitude and latitude) on geography(LINESTRING) and geography(POLYGON) columns
  • [x] Create/update/null support for geography(POINT) columns
  • [x] Create/update/null support for geography(LINESTRING) and geography(POLYGON) columns
  • [x] Integration with postgraphile-plugin-connection-filter to enable PostGIS specific filtering (via postgraphile-plugin-connection-filter-postgis)
  • [ ] Read-only support for computed attributes on geography(LINESTRING) and geography(POLYGON), such as area, length, perimeter, and centroid - currently possible by adding a plugin and consuming the GeoJSON directly.

There are many, many other features that this plugin could support - if you have specific needs please get in touch!

Usage

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

Querying and mutating

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.

In 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"
      }
    }
  }
}

Development

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