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 🙏

© 2026 – Pkg Stats / Ryan Hefner

geojson-graphql-scalars

v0.1.4

Published

GeoJSON GraphQL Scalars

Readme

GraphQL GeoJSON Scalars

geojson-graphql-scalars provides custom GraphQL scalar types for working seamlessly with GeoJSON objects, ensuring they comply with the RFC 7946 specification. This library simplifies validation and handling of GeoJSON in GraphQL queries and mutations.

Installation

npm install geojson-graphql-scalars

or with Yarn:

yarn add geojson-graphql-scalars

Features

  • Full GeoJSON Support: Includes scalars for all GeoJSON types, such as Point, LineString, Polygon, and more.

  • Robust Validation: Automatically validates GeoJSON objects to ensure compliance with the RFC 7946 format.

  • Effortless Integration: Easily add GeoJSON scalars to your GraphQL schema for enhanced functionality.

Usage

Basic Setup

Integrate the scalars into your GraphQL schema.

Type Definitions

scalar Point
scalar LineString
scalar Polygon
scalar MultiPoint
scalar MultiLineString
scalar MultiPolygon
scalar GeometryCollection
scalar Feature
scalar FeatureCollection

Resolvers

export const resolvers = {
  Point: PointScalar,
  LineString: LineStringScalar,
  Polygon: PolygonScalar,
  MultiPoint: MultiPointScalar,
  MultiLineString: MultiLineStringScalar,
  MultiPolygon: MultiPolygonScalar,
  GeometryCollection: GeometryCollectionScalar,
  Feature: FeatureScalar,
  FeatureCollection: FeatureCollectionScalar,
};

Schema Example

import { makeExecutableSchema } from '@graphql-tools/schema';
import {
  typeDefs as geojsonTypedefs,
  resolvers as geojsonResolvers,
  GeoJSONTypes,
} from '../src';

const typeDefs = `
  type Query {
    examplePoint: Point
    exampleLineString: LineString
    examplePolygon: Polygon
    exampleMultiPoint: MultiPoint
    exampleMultiLineString: MultiLineString
    exampleMultiPolygon: MultiPolygon
    exampleGeometryCollection: GeometryCollection
    exampleFeature: Feature
    exampleFeatureCollection: FeatureCollection
  }
`;

const resolvers = {
  Query: {
    examplePoint: () => ({
      type: GeoJSONTypes.Point,
      coordinates: [125.6, 10.1],
    }),
    exampleLineString: () => ({
      type: GeoJSONTypes.LineString,
      coordinates: [
        [125.6, 10.1],
        [126.0, 10.2],
      ],
    }),
    examplePolygon: () => ({
      type: GeoJSONTypes.Polygon,
      coordinates: [
        [
          [125.6, 10.1],
          [126.0, 10.2],
          [127.0, 11.0],
          [125.6, 10.1],
        ],
      ],
    }),
    exampleMultiPoint: () => ({
      type: GeoJSONTypes.MultiPoint,
      coordinates: [
        [125.6, 10.1],
        [126.0, 10.2],
      ],
    }),
    exampleMultiLineString: () => ({
      type: GeoJSONTypes.MultiLineString,
      coordinates: [
        [
          [125.6, 10.1],
          [126.0, 10.2],
        ],
        [
          [127.0, 11.0],
          [128.0, 12.0],
        ],
      ],
    }),
    exampleMultiPolygon: () => ({
      type: GeoJSONTypes.MultiPolygon,
      coordinates: [
        [
          [
            [125.6, 10.1],
            [126.0, 10.2],
            [127.0, 11.0],
            [125.6, 10.1],
          ],
        ],
      ],
    }),
    exampleGeometryCollection: () => ({
      type: GeoJSONTypes.GeometryCollection,
      geometries: [
        { type: GeoJSONTypes.Point, coordinates: [125.6, 10.1] },
        {
          type: GeoJSONTypes.LineString,
          coordinates: [
            [125.6, 10.1],
            [126.0, 10.2],
          ],
        },
      ],
    }),
    exampleFeature: () => ({
      type: GeoJSONTypes.Feature,
      geometry: {
        type: GeoJSONTypes.Point,
        coordinates: [125.6, 10.1],
      },
    }),
    exampleFeatureCollection: () => ({
      type: GeoJSONTypes.FeatureCollection,
      features: [
        {
          type: GeoJSONTypes.Feature,
          geometry: {
            type: GeoJSONTypes.Point,
            coordinates: [125.6, 10.1],
          },
        },
      ],
    }),
  },
};

export const schema = makeExecutableSchema({
  typeDefs: [geojsonTypedefs, typeDefs],
  resolvers: {
    ...geojsonResolvers,
    ...resolvers,
  },
});

Server Examples

yarn dev-apollo

or

yarn dev-yoga

or

yarn dev-graphql

Examples of server implementation is available here: examples

Example Usage

Query Example

To fetch a GeoJSON Point, you can use the following query:

query {
  examplePoint
}

Response

{
  "data": {
    "examplePoint": {
      "type": "Point",
      "coordinates": [125.6, 10.1]
    }
  }
}

Validation Rules

The library validates each GeoJSON type based on the following rules:

| GeoJSON Type | Validation Criteria | | ---------------------- | --------------------------------------------------------------------------------------------------------------------------- | | Point | coordinates must be [x, y] or [x, y, z]. | | MultiPoint | coordinates must be an array of [x, y] or [x, y, z]. | | LineString | coordinates must include at least two [x, y] points. | | MultiLineString | coordinates must be an array of LineString coordinate arrays. | | Polygon | coordinates must be an array of linear rings, each with at least four positions and closed (first and last points match). | | MultiPolygon | coordinates must be an array of Polygon coordinate arrays. | | GeometryCollection | Must include a geometries field containing an array of valid GeoJSON geometries. | | Feature | Must include a geometry field with a valid GeoJSON geometry. | | FeatureCollection | Must include a features field with an array of valid Feature objects. |