Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the point of base64 encoded IDs and how to revert this behavior? #126

Closed
paunovic opened this issue Apr 20, 2018 · 5 comments
Closed

Comments

@paunovic
Copy link

paunovic commented Apr 20, 2018

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.

@mopeyjellyfish
Copy link

You can implement your own custom Node which should solve your problem.

@fzondlo
Copy link

fzondlo commented Jan 4, 2021

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.

@erikwrede
Copy link
Member

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.

@erikwrede
Copy link
Member

erikwrede commented Feb 15, 2023

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

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants