This release is a pre-release and may not be stable for production use.
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
]
}
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-graphql-geojson-0.0.2rc1.tar.gz.
File metadata
- Download URL: django-graphql-geojson-0.0.2rc1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb7d1b3ad141c3745f7e3d8ec304c99cc9b627d302ba3a67b9b5d1c1aaa6697f
|
|
| MD5 |
b2dfbd9602fd4e29ea460a8fc4dccbe8
|
|
| BLAKE2b-256 |
21acd847bca84d9a2edbbd982791742c1ddb746ccb1480da3efb8b64dc33b0ab
|
File details
Details for the file django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl.
File metadata
- Download URL: django_graphql_geojson-0.0.2rc1-py2.py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29253b02e0593632a9e857bd034b0f98ee6dc4ac44f5a1fd668b4345909a5ee3
|
|
| MD5 |
a59736fd6a25a8d0d2579715c24dafdd
|
|
| BLAKE2b-256 |
5e9ef8c8f54d2e3b674590130696958b0cd6bf143f86fd6923b38445a01b62db
|