Skip to main content

Pypi Wheel Build Status Codecov Code Climate

GeoJSON support for Django GraphQL

Dependencies

  • Python ≥ 3.4

  • Django ≥ 1.11

Installation

Update Graphene Django package.

pip install -U git+https://github.com/graphql-python/graphene-django.git@master

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
  ]
}

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_graphql_geojson-0.0.2-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.2.tar.gz.

File metadata

File hashes

Hashes for django-graphql-geojson-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c395db5d6d941266f1747e7ec2dbde9e5b66e9b5d08249a4bbbd325a5f072972
MD5 ebb02171e0a3242a2223cd46221b1a9f
BLAKE2b-256 0ba4963823468e18b51746b4c9c2a551a59f0793570ea949a105c14cf82bd973

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_graphql_geojson-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ec21e71e7a023cb77df62b63b417fa5176f72380b01ab42466816c4a3463681d
MD5 c5a0f6f2a3d3217c8a201d7af65a0a5e
BLAKE2b-256 2b7bd0c80e9510502e691ac4287302160e22f7de4bd3c04c177f0af72f33e92b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.3

2 files

This release

0.0.2 This release

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page