github graphql-python/graphene v3.3.0

latest releases: v3.4.1, v3.4.0
15 months ago

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: graphql/graphql-spec#867

What's Changed

  • Default enum description to "An enumeration." by @firaskafri in #1502
  • Allow the user to change InputObjectType's default value on non-specified inputs to a sentinel value by @flipbit03 in #1506
  • 881: Corrected enum metaclass to fix pickle.dumps() by @senseysensor in #1495
  • chore: Use typing.TYPE_CHECKING instead of MYPY by @rapsealk in #1503
  • test: print schema with InputObjectType with DateTime field with default_value (#1293) by @ransomw in #1513
  • docs: add get_human function by @conao3 in #1380
  • CI: drop python 3.6 by @dulmandakh in #1507
  • types: add option for strict connection types by @shrouxm in #1504

New Contributors

Full Changelog: v3.2.2...v3.3.0

Don't miss a new graphene release

NewReleases is sending notifications on new releases.