GeoJSON support for Django GraphQL
Project description
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
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.2rc1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb7d1b3ad141c3745f7e3d8ec304c99cc9b627d302ba3a67b9b5d1c1aaa6697f |
|
MD5 | b2dfbd9602fd4e29ea460a8fc4dccbe8 |
|
BLAKE2b-256 | 21acd847bca84d9a2edbbd982791742c1ddb746ccb1480da3efb8b64dc33b0ab |
Close
Hashes for django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29253b02e0593632a9e857bd034b0f98ee6dc4ac44f5a1fd668b4345909a5ee3 |
|
MD5 | a59736fd6a25a8d0d2579715c24dafdd |
|
BLAKE2b-256 | 5e9ef8c8f54d2e3b674590130696958b0cd6bf143f86fd6923b38445a01b62db |