GeoJSON support for Django GraphQL
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-graphql-geojson-0.0.2rc2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7191b11f0fcd43186fd4c414e2cfe5e380bb6a7d7ecd0145f0f7f9f45c7eb23 |
|
MD5 | 78923c615f28bc10cdd5fa1f97849f57 |
|
BLAKE2b-256 | 311e52318ab514e392eca514cce3687451e324286ca81430c17aed6574d8b09b |
Close
Hashes for django_graphql_geojson-0.0.2rc2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59dcc391f7772bdc841353f556960297a2665d5c786bf80384a757b5b4bca839 |
|
MD5 | cc6ca69f43933bf1eb30967066e8fe67 |
|
BLAKE2b-256 | 551b1a16a62405846776e4deaa8f47d4314ad942e6e60d8a3c3862f178053df5 |