MyGit

v3.2.0

graphql-python/graphene

版本发布时间: 2022-12-09 18:20:13

graphql-python/graphene最新发布版本:v3.3.0(2023-07-26 14:47:55)

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:

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: https://github.com/graphql-python/graphene/compare/v3.1.1...v3.2.0

相关地址:原始地址 下载(tar) 下载(zip)

查看:2022-12-09发行的版本