eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 106 forks source link

How to deal with PointField and GeoDjango fields? #45

Open shalakhin opened 6 years ago

shalakhin commented 6 years ago

It seems that using https://github.com/flavors/django-graphql-geojson raises error here:

Exception: Don't know how to convert the Django field
eamigo86 commented 6 years ago

Hi @shalakhin, I will check it. Thanks for report

bgsuello commented 5 years ago

Nevermind.

supporting other field type is:

# converter.py

from django.contrib.gis.db.models.fields import PointField
from graphene import String
from graphene_django_extras.utils import is_required
from graphene_django_extras.converter import convert_django_field

@convert_django_field.register(PointField)
def convert_pointfield_to_string(field, registry=None, input_flag=None, nested_fields=False):
    return String(description=field.help_text or field.verbose_name,
                  required=is_required(field) and input_flag == 'create')
# types.py

from graphene_django_extras import DjangoSerializerType
from .filters import MyFilters
from .serializers import MySerializer
from .converter import *

class MyModelType(DjangoSerializerType):
    class Meta:
        serializer_class = MySerializer
        filterset_class = MyFilters
# schema.py
import graphene
from .types import MyModelType

class MyQuery(graphene.ObjectType):
    stores = MyModelType.ListField(description='List of stores.')

Any solution for this?

Exception: Don't know how to convert the Django field Store.location (<class 'django.contrib.gis.db.models.fields.PointField'>)
dennisbr91 commented 2 years ago

Any solutions for this questions..?