Metadata-Version: 2.0
Name: django-graphql-geojson
Version: 0.0.2rc2
Summary: GeoJSON support for Django GraphQL
Home-page: https://github.com/flavors/django-graphql-geojson/
Author: mongkok
Author-email: domake.io@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 1 - Planning
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Requires-Dist: Django (>=1.11)
Requires-Dist: graphene-django (>=2.0.0)

Django GraphQL GeoJSON
======================

|Pypi| |Wheel| |Build Status| |Codecov| |Code Climate|

`GeoJSON`_ support for `Django GraphQL`_

.. _GeoJSON: http://geojson.org
.. _Django GraphQL: https://github.com/graphql-python/graphene-django


Dependencies
------------

* Python ≥ 3.4
* Django ≥ 1.11


Installation
------------

Pending pull request

.. code:: sh

    pip install -I git+https://github.com/mongkok/graphene-django@default-meta#egg=graphene-django

Install last stable version from Pypi.

.. code:: sh

    pip install django-graphql-geojson


GeoJSONType
-----------

``models.py``

.. code:: python

    from django.contrib.gis.db import models


    class Place(models.Model):
        name = models.CharField(max_length=255)
        location = models.PointField()



``schema.py``

.. code:: python

    from graphql_geojson.types import GeoJSONType


    class PlaceType(GeoJSONType):

        class Meta:
            model = models.Place
            geojson_field = 'location'


**Query**

.. code::

    query {
      places {
        id
        type
        geometry {
          type
          coordinates
        }
        properties {
          name
        }
      }
    }


GeoJSONInput
------------

``schema.py``

.. code:: python

    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**

.. code::

    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):

.. code:: python

    'POINT(5 23)'

- Hexadecimal (HEX):

.. code:: python

    '010100000000000000000014400000000000003740'

- GeoJSON:

.. code:: python

    {
      "type": "Point",
      "coordinates": [
        5.000000,
        23.000000
      ]
    }


.. |Pypi| image:: https://img.shields.io/pypi/v/django-graphql-geojson.svg
   :target: https://pypi.python.org/pypi/django-graphql-geojson

.. |Wheel| image:: https://img.shields.io/pypi/wheel/django-graphql-geojson.svg
   :target: https://pypi.python.org/pypi/django-graphql-geojson

.. |Build Status| image:: https://travis-ci.org/flavors/django-graphql-geojson.svg?branch=master
   :target: https://travis-ci.org/flavors/django-graphql-geojson

.. |Codecov| image:: https://img.shields.io/codecov/c/github/flavors/django-graphql-geojson.svg
   :target: https://codecov.io/gh/flavors/django-graphql-geojson

.. |Code Climate| image:: https://api.codeclimate.com/v1/badges/67dbb917ad4cf8c422a6/maintainability
   :target: https://codeclimate.com/github/flavors/django-graphql-geojson


