graphene/UPGRADE-v2.0.md

1.8 KiB

v2.0 Upgrade Guide

  • ObjectType, Interface, InputObjectType, Scalar and Enum implementations have been quite simplified, without the need of define a explicit Metaclass. The metaclasses threfore are now deleted as are no longer necessary, if your code was depending on this internal metaclass for creating custom attrs, please see an example of how to do it now in 2.0.

Deprecations

  • AbstractType is deprecated, please use normal inheritance instead.

Before:

class CommonFields(AbstractType):
    name = String()

class Pet(CommonFields, Interface):
    pass

With 2.0:

class CommonFields(object):
    name = String()

class Pet(CommonFields, Interface):
    pass
  • Meta options as class arguments (ONLY PYTHON 3).

    Before:

    class Dog(ObjectType):
        class Meta:
            interfaces = [Pet]
        name = String()
    

    With 2.0:

    class Dog(ObjectType, interfaces=[Pet]):
        name = String()
    

Breaking Changes

  • Node types no longer have a Connection by default. In 2.0 and onwoards Connections should be defined explicitly.

    Before:

    class User(ObjectType):
        class Meta:
            interfaces = [relay.Node]
        name = String()
    
    class Query(ObjectType):
        user_connection = relay.ConnectionField(User)
    

    With 2.0:

    class User(ObjectType):
        class Meta:
            interfaces = [relay.Node]
        name = String()
    
    class UserConnection(relay.Connection):
        class Meta:
            node = User
    
    class Query(ObjectType):
        user_connection = relay.ConnectionField(UserConnection)