v3.3.0
版本发布时间: 2023-07-26 14:47:55
graphql-python/graphene最新发布版本:v3.3.0(2023-07-26 14:47:55)
This release brings two new features and several fixes and semantic upgrades due to new Python features. Thanks to everyone that contributed! 😊
Default value for InputObjectTypes
⚠️⚠️ACTION REQUIRED⚠️⚠️
In GraphQL, inputs can have fields which are optional. Currently, if those fields are not specified in the query, they are passed to the python inputs as None
. This renders them indistinguishable from fields that are actually passed to the query with a value of null
. While the alternative would be to check the definition via "key" in input
, it is more accessible to mark these fields as explicitly UNDEFINED
.
This PR adds a new global override, which allows unspecified fields to be set to graphql.UNDEFINED
. In the future, the default Value will be set to UNDEFINED
, making this a soft migration and deprecation of the previous situation.
This is a soft migration. Long-Term, the Input Objects will ALWAYS contain the value UNDEFINED
Make sure your code supports these cases in None
checks. After the default has been set to UNDEFINED
, you will still be able to switch back to None
for the foreseeable future.
Strict connection types support in Relay
Custom Relay connection classes can now be made NonNull
using the strict_types
option on the connection meta.
Using this example
class MyObjectConnection(Connection):
class Meta:
node = MyObject
strict_types = True
will change from
type MyObjectConnection {
edges: [MyObjectEdge]
}
to
type MyObjectConnection {
edges: [MyObjectEdge!]!
}
Caveats
We want to make sure you're informed about using NonNull relay connections. While they are a great way to get rid of some null checks in typed frontends, it's important to be mindful of error handling with these connections. When working with NonNull connections, it's crucial to remember that if a requested field or edge is not available or the resolver throws an error, the error will bubble up to the next nullable parent field, which is oftentimes the root node. That way, you cannot handle partial results in case of partial errors anymore. In a nullable connection, only the nullable fields will be set to null and the error will not bubble up.
To address this, we recommend considering waiting for the future release of client-controlled nullability for cases where certain connections might be nullable. By opting for client-controlled nullability, you gain more control over error handling, enabling you to handle potential null values more gracefully and enhance the overall user experience. Read more about client controlled nullability here: https://github.com/graphql/graphql-spec/issues/867
What's Changed
- Default enum description to "An enumeration." by @firaskafri in https://github.com/graphql-python/graphene/pull/1502
- Allow the user to change InputObjectType's default value on non-specified inputs to a sentinel value by @flipbit03 in https://github.com/graphql-python/graphene/pull/1506
- 881: Corrected enum metaclass to fix pickle.dumps() by @senseysensor in https://github.com/graphql-python/graphene/pull/1495
- chore: Use
typing.TYPE_CHECKING
instead of MYPY by @rapsealk in https://github.com/graphql-python/graphene/pull/1503 - test: print schema with InputObjectType with DateTime field with default_value (#1293) by @ransomw in https://github.com/graphql-python/graphene/pull/1513
- docs: add get_human function by @conao3 in https://github.com/graphql-python/graphene/pull/1380
- CI: drop python 3.6 by @dulmandakh in https://github.com/graphql-python/graphene/pull/1507
- types: add option for strict connection types by @shrouxm in https://github.com/graphql-python/graphene/pull/1504
New Contributors
- @firaskafri made their first contribution in https://github.com/graphql-python/graphene/pull/1502
- @senseysensor made their first contribution in https://github.com/graphql-python/graphene/pull/1495
- @rapsealk made their first contribution in https://github.com/graphql-python/graphene/pull/1503
- @ransomw made their first contribution in https://github.com/graphql-python/graphene/pull/1513
- @dulmandakh made their first contribution in https://github.com/graphql-python/graphene/pull/1507
- @shrouxm made their first contribution in https://github.com/graphql-python/graphene/pull/1504
Full Changelog: https://github.com/graphql-python/graphene/compare/v3.2.2...v3.3.0