/graphql-geojson

GraphQL schema object types for GeoJSON

Primary LanguageJavaScript

graphql-geojson

npm version

GraphQL schema object types for GeoJSON. Based on GeoJSON Object Schema.

Installation

npm i -S graphql-geojson

or with Yarn:

yarn add graphql-geojson

Usage

import { GraphQLObjectType, GraphQLSchema } from 'graphql'
import { PointObject } from 'graphql-geojson'

export default new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: () => ({
      point: {
        type: PointObject,
        resolve: () => ({
          type: 'Point',
          coordinates: [-105.01621, 39.57422],
          crs: {
            type: 'name',
            properties: {
              name: 'urn:ogc:def:crs:OGC:1.3:CRS84',
            },
          },
        }),
      },
    }),
  }),
})

Then you can query it like this:

query {
  point {
    type
    coordinates
    crs {
      type
      properties {
        ... on GeoJSONNamedCRSProperties {
          name
        }
      }
    }
  }
}

Demo

An example GraphQL server implementation is available here: https://github.com/ghengeveld/graphql-geojson-demo