question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to declare custom global ID

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
metakotcommented, Nov 29, 2018

I think the people behind the graphene-django missed out how confusing, frustrating and all other dirty epithets is to work with shadowed-out id of an object.

9reactions
metakotcommented, Dec 12, 2018

@webel

how to get an object with its model pk

class ShipNode(DjangoObjectType):
    pk = graphene.Int(source='pk')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Global IDs (Data Management)
ArcGIS geoprocessing tool that adds global IDs to a list of geodatabase feature classes, tables, and feature datasets.
Read more >
Specifying the global ID attribute for users and groups
Decide if you will accept the default identifiers used by your LDAP directory server or create a custom attribute to be used as...
Read more >
What are Global, Custom, and Family IDs?
What are Global, Custom, and Family IDs? ... There are three types of ID described below. ... Custom ID: a user defined ID...
Read more >
Pass Global ID from Collector to G
Pass Global ID from Collector to G · The first field (let's cal it "incoming") should be a hidden field (or text, if...
Read more >
Global ID
Global IDs are identifiers of items that are connected through synchronization. While every item has its own unique ID (which is also the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found