v3.2.0
版本发布时间: 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:
-
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:
- feat: Add support for custom global (Issue #1276) by @tcleonard in https://github.com/graphql-python/graphene/pull/1428
Fixes & Improvements:
- Regression fix: (graphene 2->3)
ObjectTypes
can be copied again #1333 by @keu210 - Fix: Enums can now have members called
description
: #1478 by @mike-roberts-healx - Enums are now hashable: #1461 by @bkad
- Enums are now iterable: #1473 by @rgroothuijsen
- Dependency on unused promise Library was removed: #1476 by @mike-roberts-healx
- Docs improvements by @rgroothuijsen
All Changes
- feat: Add support for custom global (Issue #1276) by @tcleonard in https://github.com/graphql-python/graphene/pull/1428
- Add copy function for GrapheneGraphQLType by @keu210 in https://github.com/graphql-python/graphene/pull/1463
- hashable Enum by @bkad in https://github.com/graphql-python/graphene/pull/1461
- Clarify execution order in middleware docs by @rgroothuijsen in https://github.com/graphql-python/graphene/pull/1475
- fix: MyPy findings due to a mypy version upgrade were corrected by @erikwrede in https://github.com/graphql-python/graphene/pull/1477
- Disambiguate argument name in quickstart docs by @rgroothuijsen in https://github.com/graphql-python/graphene/pull/1474
- Make Graphene enums iterable like Python enums by @rgroothuijsen in https://github.com/graphql-python/graphene/pull/1473
- Remove unnecessary dependency on 'promise' library by @mike-roberts-healx in https://github.com/graphql-python/graphene/pull/1476
- Do not interpret Enum members called 'description' as description properties by @mike-roberts-healx in https://github.com/graphql-python/graphene/pull/1478
New Contributors
- @keu210 made their first contribution in https://github.com/graphql-python/graphene/pull/1463
- @bkad made their first contribution in https://github.com/graphql-python/graphene/pull/1461
- @rgroothuijsen made their first contribution in https://github.com/graphql-python/graphene/pull/1475
- @mike-roberts-healx made their first contribution in https://github.com/graphql-python/graphene/pull/1476
Full Changelog: https://github.com/graphql-python/graphene/compare/v3.1.1...v3.2.0