Skip to content
Jonathan Kim edited this page Jul 11, 2020 · 21 revisions

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.

Python compatibility

Graphene 3.0 drops support for Python 2.x and now supports Python 3.6, 3.7, and 3.8.

What's new in Graphene v3

GraphQL-core v3

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.

Better Enum support

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"

⚠️ This is a breaking change. You will need to update any resolvers or mutations that accept enums as inputs to support this change. ⚠️

Ref: https://github.com/graphql-python/graphene/pull/1153

Fast ObjectType creation

TODO

Base64 scalar

TODO

Subscription support

TODO

Other new features

Backwards incompatible changes in 3.0

Backends support removed

TODO

Enum inputs

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

Clone this wiki locally