I have noticed that if I base 64 decode the id field that I can get the
Also is there any way to get a Relay.Node by id rather than the unique id?
You can convert the base64 id into your id by using from_global_id
from graphql_relay.node.node import from_global_id
from_global_id returns a tuple of (type, id)
As for filtering by your id:
You can make your own filter to grab the node by your id on your object node field have it take in a custom value and filter by that
I was able to do this by adding an _id field to the Django Object Type with a simple custom resolver:
def id_resolver(self, *_):
return self.id
node = type('{model_name}Node'.format(model_name=model_name),
(DjangoObjectType,),
dict(
Meta=meta_class,
_id=Int(name='_id'),
resolve__id=id_resolver
)
)
Hi @timothyjlaurent I'm having the same issue right now, apprently the ID type is a base64 encoded String of this string pattern "model:id" when setting up a DjangoObjectType entity.
I'm working on trying to find the appropriate solution instead of manually decoding the base64 string.
I feel like the solution you employed is a nice workaround but not a true solution to the problem.
I think the issue is worth opening
Most helpful comment
You can convert the base64 id into your id by using from_global_id
from graphql_relay.node.node import from_global_idfrom_global_id returns a tuple of (type, id)
As for filtering by your id:
You can make your own filter to grab the node by your id on your object node field have it take in a custom value and filter by that