Skip to content

How to declare custom global ID #349

Open
@samkit-jain

Description

@samkit-jain

Code

class ShipNode(DjangoObjectType):
    class Meta:
        model = Ship
        filter_fields = ['id', 'size']
        interfaces = (relay.Node, )
    
    rowid = graphene.String()
    
    @resolve_only_args
    def resolve_rowid(self):
        return self.id

class Query(object):
    ship = relay.Node.Field(ShipNode)
    all_ships = DjangoFilterConnectionField(ShipNode)

I have an id field in my database which gets override when querying GraphQL server by the custom global ID. Using resolve_rowid, I can get the id I want, but I am unable to use it in the filters.

query {
    ship(id: "124567") {
    }
 }

How can I filter based on my database's primary key instead of the global ID? How can I rename global ID from id to _id?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions