graphene-sqlalchemy
graphene-sqlalchemy copied to clipboard
What's the point of base64 encoded IDs and how to revert this behavior?
Library returns B64 encoded ID fields instead normal int IDs as they are defined in my models. Right now I am using workaround where I define custom row_id field and resolver for each model:
class CertificationGraphQL(CountableSQLAlchemyObjectType):
class Meta:
model = Certification
interfaces = (Node, )
row_id = BigInt()
def resolve_row_id(self, info):
return self.id
Can I globally disable B64 IDs? This is similar question as the issue #102.
I tried putting following code in my graphql/models.py file to try to revert this behavior:
@convert_sqlalchemy_type.register(BigInteger)
def convert_column_to_int_or_id(type, column, registry=None):
return BigInt(description=get_column_doc(column),
required=not (is_column_nullable(column)))
...but no dice. Graphene still converts id fields to B64 encoded pairs.
Any insight would be appreciated.
You can implement your own custom Node which should solve your problem.
Agree with @paunovic on this one. Would be nice if there was an easy way to disable this behavior. Or better yet, have it disabled by default. Seems like this is adding complexity for the sake of complexity.
The IDs we got back were base64 strings. IDs are designed to be opaque (the only thing that should be passed to the id argument on node is the unaltered result of querying id on some object in the system), and base64ing a string is a useful convention in GraphQL to remind viewers that the string is an opaque identifier.
https://relay.dev/docs/guides/graphql-server-specification/
This is a quote from the relay GQL Server spec. Since our repo follows that implementation, I think we should stick to Spec, but enable users to customize this behavior without having to implement custom nodes. I'm open to suggestions on how to achieve that or further discussion.
This was solved by the customizable GlobalIDType in graphene 3.2:
https://github.com/graphql-python/graphene/releases/tag/v3.2.0
You can add a GlobalIDType that doesn't convert the IDs to Base64 and doesn't add any Type Info to the ID, or use SimpleGlobalIDType, please have a look at the release notes for an example.
https://github.com/loft-orbital/graphene/blob/d1f6412bbb2588404584616a4390fecb58f746f9/graphene/relay/id_type.py
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.