Skip to main content

GeoJSON support for Django GraphQL

Project description

Pypi Wheel Build Status Codecov Code Climate

GeoJSON support for Django GraphQL

Dependencies

  • Python ≥ 3.4

  • Django ≥ 1.11

Installation

Install last stable version from Pypi.

pip install django-graphql-geojson --process-dependency-links

GeoJSONType

models.py

from django.contrib.gis.db import models


class Place(models.Model):
    name = models.CharField(max_length=255)
    location = models.PointField()

schema.py

from graphql_geojson.types import GeoJSONType


class PlaceType(GeoJSONType):

    class Meta:
        model = models.Place
        geojson_field = 'location'

Query

query {
  places {
    id
    type
    geometry {
      type
      coordinates
    }
    properties {
      name
    }
  }
}

GeoJSONInput

schema.py

import graphene

from graphql_geojson.types import GeoJSONInput


class CreatePlace(graphene.Mutation):
    place = graphene.Field(types.PlaceType)

    class Arguments:
        name = graphene.String(required=True)
        location = GeoJSONInput(required=True)

    @classmethod
    def mutate(cls, root, info, **args):
        place = models.Place.objects.create(**args)
        return cls(place=place)

Mutation

mutation CreatePlace($name: String!, $location: GeoJSONInput!) {
  createPlace(name: $name, location: $location) {
    place {
      id
    }
  }
}

GeoJSONInput object may be initialized in a few ways:

  • Well-known text (WKT):

'POINT(5 23)'
  • Hexadecimal (HEX):

'010100000000000000000014400000000000003740'
  • GeoJSON:

{
  "type": "Point",
  "coordinates": [
    5.000000,
    23.000000
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-graphql-geojson-0.0.2rc1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl (6.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-graphql-geojson-0.0.2rc1.tar.gz.

File metadata

File hashes

Hashes for django-graphql-geojson-0.0.2rc1.tar.gz
Algorithm Hash digest
SHA256 fb7d1b3ad141c3745f7e3d8ec304c99cc9b627d302ba3a67b9b5d1c1aaa6697f
MD5 b2dfbd9602fd4e29ea460a8fc4dccbe8
BLAKE2b-256 21acd847bca84d9a2edbbd982791742c1ddb746ccb1480da3efb8b64dc33b0ab

See more details on using hashes here.

File details

Details for the file django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 29253b02e0593632a9e857bd034b0f98ee6dc4ac44f5a1fd668b4345909a5ee3
MD5 a59736fd6a25a8d0d2579715c24dafdd
BLAKE2b-256 5e9ef8c8f54d2e3b674590130696958b0cd6bf143f86fd6923b38445a01b62db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page