graphql-python / graphql-python/graphene-django

How to declare custom global ID

Open
#349 10 comments 5 reactions 0 assignees View on GitHub
✨enhancement 👀 more info needed wontfix
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

Code
```python
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.

```python
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`?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.