github graphql-python/graphene v3.2.0

latest releases: v3.3.0, v3.2.2, v3.2.1...
19 months ago

What's Changed

Support for custom global IDs in relay.Node

The global ID type of a Node can now be customized:

class CustomNode(Node):
    class Meta:
        global_id_type = CustomGlobalIDType


class User(ObjectType):
    class Meta:
        interfaces = [CustomNode]

    name = String()

    @classmethod
    def get_node(cls, _type, _id):
        return self.users[_id]
Available Types

Currently, the following types are available:

  • DefaultGlobalIDType: Default global ID type: base64 encoded version of ": ". (Previously the only option) Scalar: ID
  • SimpleGlobalIDType : Simple global ID type: simply the id of the object. Scalar: ID
  • UUIDGlobalIDType : UUID global ID type. Scalar: UUID
Customization

To create a custom global type, BaseGlobalIDType must be extended:

class CustomGlobalIDType(BaseGlobalIDType):

    graphene_type = CustomScalar

    @classmethod
    def resolve_global_id(cls, info, global_id):
        _type = custom_get_type_from_global_id(global_id)
        return _type, global_id

    @classmethod
    def to_global_id(cls, _type, _id):
        return _id

graphene_type specifies the type of scalar to be used in the schema. Remember, that if you're using ID as a scalar, you might need to deserialize your custom global ID first!

Relevant PR:

Fixes & Improvements:

All Changes

New Contributors

Full Changelog: v3.1.1...v3.2.0

Don't miss a new graphene release

NewReleases is sending notifications on new releases.