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

Pending pull request

pip install -I git+https://github.com/mongkok/graphene-django@default-meta#egg=graphene-django

Install last stable version from Pypi.

pip install django-graphql-geojson

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.2rc2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

django_graphql_geojson-0.0.2rc2-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

File hashes

Hashes for django-graphql-geojson-0.0.2rc2.tar.gz
Algorithm Hash digest
SHA256 e7191b11f0fcd43186fd4c414e2cfe5e380bb6a7d7ecd0145f0f7f9f45c7eb23
MD5 78923c615f28bc10cdd5fa1f97849f57
BLAKE2b-256 311e52318ab514e392eca514cce3687451e324286ca81430c17aed6574d8b09b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_graphql_geojson-0.0.2rc2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 59dcc391f7772bdc841353f556960297a2665d5c786bf80384a757b5b4bca839
MD5 cc6ca69f43933bf1eb30967066e8fe67
BLAKE2b-256 551b1a16a62405846776e4deaa8f47d4314ad942e6e60d8a3c3862f178053df5

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