GeoJSON support for Django GraphQL
Project description
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
]
}
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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c395db5d6d941266f1747e7ec2dbde9e5b66e9b5d08249a4bbbd325a5f072972 |
|
MD5 | ebb02171e0a3242a2223cd46221b1a9f |
|
BLAKE2b-256 | 0ba4963823468e18b51746b4c9c2a551a59f0793570ea949a105c14cf82bd973 |
Close
Hashes for django_graphql_geojson-0.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec21e71e7a023cb77df62b63b417fa5176f72380b01ab42466816c4a3463681d |
|
MD5 | c5a0f6f2a3d3217c8a201d7af65a0a5e |
|
BLAKE2b-256 | 2b7bd0c80e9510502e691ac4287302160e22f7de4bd3c04c177f0af72f33e92b |