django-graphql-geojson icon indicating copy to clipboard operation
django-graphql-geojson copied to clipboard

Using of this module makes types to be incompatible with custom interfaces

Open artemnesterenko opened this issue 6 years ago • 4 comments

I have several types for which I want to make a search. I've created a Searchable interface which requires a displayName field to be in a type and I've added the field to all appropriate types. But a type inherited from GeoJSONType doesn't conform to the Searchable interface eventually, because it's displayName is located in properties. How can I make things work properly?

artemnesterenko avatar Jun 27 '18 05:06 artemnesterenko

Hi @artemnesterenko,

All declared fields from a GeoJSONType class are moved to properties field, we could add a field within GeoJSONType.Meta to exclude some properties.

Could you paste the code for the Searchable interface?

mongkok avatar Jun 29 '18 18:06 mongkok

Hi @mongkok!

from django.contrib.gis.db import models
from graphene import Interface, NonNull, String, Node
import graphql_geojson

class MyModel(models.Model):
    name = models.CharField(max_length=32, blank=False, null=False)
    location = models.MultiPolygonField(blank=True, null=True)

class Searchable(Interface):
    display_name = NonNull(String)

class MyGeoType(graphql_geojson):
    display_name = NonNull(String)

    def resolve_display_name(self, info, **kwargs):
        return self.name
    
    class Meta:
        model = MyModel
        geojson_field = 'location'
        interfaces = (Node, Searchable)

So, interface fields can be defined not only in models themselves but also in GraphQL types.

artemnesterenko avatar Jul 02 '18 05:07 artemnesterenko

Any update on this?

artemnesterenko avatar Jul 19 '18 08:07 artemnesterenko

Hi @artemnesterenko, I am sorry for the long long delay to response.

Graphene interfaces are not compatible for GeoJSONType. I am trying to move the interfaces fields within the properties field but I can not find an easy way to do this, I will keep you updated with new changes

mongkok avatar Aug 12 '18 18:08 mongkok