Graphene-django: DjangoFilterConnectionField without relay

Created on 12 Apr 2017  路  4Comments  路  Source: graphql-python/graphene-django

Hi, I'm considering using graphql without relay. However, it seems like DjagnoFilterConnectionField is coupled with relay. I wish to not implement the base64 encoded <type>:<id> that relay.Node is using. Has anyone used graphene-django without relay yet?

Most helpful comment

Hi, I've found what I needed:

    def get_node_from_global_id(id, context, info, only_type=None):
        return info.return_type.graphene_type._meta.model.objects.get(id=id)

Closing issue :)

All 4 comments

After digging in into the code, I realized that it can be achieved with custom nodes. A follow up question:

class CustomNode(Node):

    class Meta:
        name = 'Node'

    @staticmethod
    def to_global_id(type, id):
        return id

    @staticmethod
    def get_node_from_global_id(id, context, info, only_type=None):
        # todo: fetch entity via model.objects.get

How do I get access to the right model on the resolver? Thanks!

Hi, I've found what I needed:

    def get_node_from_global_id(id, context, info, only_type=None):
        return info.return_type.graphene_type._meta.model.objects.get(id=id)

Closing issue :)

Can you provide full example code? What is thisNode you used?

Sorry I don't have an example code anymore. The Node class should be the one from the package graphene.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MilanRgm picture MilanRgm  路  3Comments

StefanoSega picture StefanoSega  路  4Comments

ZuluPro picture ZuluPro  路  3Comments

flame0 picture flame0  路  4Comments

MythicManiac picture MythicManiac  路  3Comments