-
Notifications
You must be signed in to change notification settings - Fork 822
v3 release notes
Welcome to Graphene v3!
This is our biggest ever release and brings Graphene up to date with the latest changes in the GraphQL spec as well as delivering some new features and bug fixes. Since this is a major version release there are some backwards incompatible changes you’ll want to be aware of when upgrading from Graphene 2.1 or earlier.
Graphene 3.0 drops support for Python 2.x and now supports Python 3.6, 3.7, and 3.8.
Graphene builds on top of the excellent GraphQL-core library which is a direct port of the reference GraphQL.js library. Graphene v3 now uses GraphQL-core v3 which is a significant update from v2 bringing lots of new language features and other improvements.
Graphene v3 introduces better Enum support which should improve the developer experience of working with them in Graphene. Previously when resolving an Enum you had to return the Enum value from the field resolver. In v3 you can now return the Enum member directly:
from graphene import Enum, ObjectType, Schema
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
class Query(ObjectType):
color = Color(required=True)
def resolve_color(root, info):
return Color.RED
schema = Schema(query=Query)
result = schema.execute("query { color }")
assert result.data["color"] == "RED"
(This change is completely backwards compatible so any resolvers that return the member value will still work)
Also when Enum's are used as an input to a field the resolver now receives the Enum member directly rather than the value:
from graphene import Enum, ObjectType, Schema
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
class Query(ObjectType):
color = Color(required=True, color_input=Color(required=True))
def resolve_color(root, info, color_input):
assert color_input is Color.RED
return color_input
schema = Schema(query=Query)
result = schema.execute("query { color(colorInput: RED) }")
assert result.data["color"] == "RED"
Ref: https://github.com/graphql-python/graphene/pull/1153
TODO
TODO
TODO
- Better error messages when relay
global_id
fails to parse (https://github.com/graphql-python/graphene/pull/1074) - Graphene now accepts plain GraphQL types as well as Graphene types (https://github.com/graphql-python/graphene/pull/1224)
TODO
As outlined above: if a field takes an Enum as an input the resolver will now get passed the Enum member rather than the member value.
For example, given the following schema:
from graphene import Enum, ObjectType, String, Schema
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
class Query(ObjectType):
color = String(color_input=Color(required=True))
def resolve_color(root, info, color_input):
return color_input
schema = Schema(query=Query)
Before:
result = schema.execute("query { color(colorInput: RED) }")
assert result.data["color"] == "1"
After:
result = schema.execute("query { color(colorInput: RED) }")
assert result.data["color"] == "EnumMeta.RED"
A huge thanks to everyone involved in bringing this release together!
Full changelog https://github.com/graphql-python/graphene/compare/v2.1.8...v3.0.0