graphene-django-extras icon indicating copy to clipboard operation
graphene-django-extras copied to clipboard

No docs on overriding a field

Open kneufeld opened this issue 6 years ago • 1 comments

I had a lot of difficulty getting a django BinaryField overridden and I'm not sure if I did it correctly but it seems to work.

graphene_django.extras.converter.convert_binary_to_string doesn't seem to get called/registered no matter how/when I import it. I couldn't find any docs/examples/tests anywhere showing how to make use of the converter functions but I may have just missed them somehow.

Maybe the docs just need an example?

Here's how I got something working...

# models.py
from django.db import models

class Venue(models.Model):
    name = models.CharField(max_length=128)
    icon = models.BinaryField(null=True)
# schema.py

import graphene
from graphene import relay, ObjectType, Schema
from graphene_django.types import DjangoObjectType
from graphene_django.filter import DjangoFilterConnectionField
from graphene_django_extras.base_types import Binary

from backend.models import Venue

class VenueNode(DjangoObjectType):
    class Meta:
        model = Venue
        exclude_fields = ('icon',) # must exclude first!!!

        icon    = graphene.Field(Binary)

class Query(ObjectType):
    venue = relay.Node.Field(VenueNode)
    all_venues = DjangoFilterConnectionField(VenueNode)

schema = Schema(query=Query)

kneufeld avatar Jan 16 '19 17:01 kneufeld