graphene-sqlalchemy comes with pre-defined connection fields to quickly create a functioning relay API. Using the SQLAlchemyConnectionField, you have access to relay pagination, sorting and filtering (filtering is coming soon!).

To be used in a relay connection, your SQLAlchemyObjectType must implement the Node interface from graphene.relay. This handles the creation of the Connection and Edge types automatically.

The following example creates a relay-paginated connection:

class Pet(Base):
    __tablename__ = 'pets'
    id = Column(Integer(), primary_key=True)
    name = Column(String(30))
    pet_kind = Column(Enum('cat', 'dog', name='pet_kind'), nullable=False)

class PetNode(SQLAlchemyObjectType):
    class Meta:
        model = Pet

class Query(ObjectType):
    all_pets = SQLAlchemyConnectionField(PetNode.connection)

To disable sorting on the connection, you can set sort to None the SQLAlchemyConnectionField:

class Query(ObjectType):
    all_pets = SQLAlchemyConnectionField(PetNode.connection, sort=None)