Skip to content

3.0.0b2

Pre-release
Pre-release
Compare
Choose a tag to compare
@erikwrede erikwrede released this 15 Jul 09:35
· 34 commits to master since this release
dfee3e9

What's Changed

Extended Support for hybrid_property

In older versions, hybrid properties of an SQLAlchemy model were converted to Strings in the SQLAlchemyObjectType, unless overridden by an ORMField. This release includes support for automatic type detection based on the type hints of the method.

Old Behavior

class Interval(Base):

    id = Column(Integer, primary_key=True)
    start = Column(Integer, nullable=False)
    end = Column(Integer, nullable=False)

    @hybrid_property
    def length(self):
        return self.end - self.start

class GQLInterval(SQLAlchemyObjectType):
    class Meta:
        model = Interval

GraphQL Schema:

type Interval {
  id: ID!
  start: Int!
  end: Int!
  length: String
}

New Behavior

class Interval(Base):
    #Fields from above

    @hybrid_property
    def length(self) -> int:
        return self.end - self.start

class GQLInterval(SQLAlchemyObjectType):
    class Meta:
        model = Interval

GraphQL Schema:

type Interval {
  id: ID!
  start: Int!
  end: Int!
  length: Int
}

The feature supports all basic python types (#340) , ObjectTypes and Unions of ObjectTypes (Union[T1,T2] or 3.10-style: T1 | T2).
Adding additional converters is possible similar to column type converters using @convert_sqlalchemy_hybrid_property_type.register(matcher). See converter.py for examples.

This feature is experimental and subject to extension (NonNull Support, Hybrid Methods, @property support). If you encounter an issue, see room for improvement or want to help extend the feature, please open an issue!

  • Support setting @hybrid_property's return type from the functions type annotations. by @flipbit03 in #340
  • Supplant @hybrid_property's type annotation support with Optional[T] by @flipbit03 in #343

Docstring Support for hybrid_property

The default behavior was changed to include the docstrings of hybrid property methods into the schema, similar to the docstrings of the column. This can be overridden using an ORMField providing an empty docstring.

  • Pick up the docstrings of hybrid properties by @bim9262 in #344

Changes to existing Column Type converters

This PR brought updates and additions to type converters. Some type converters were adjusted to map to the correct graphene scalar type. The changes might reflect in your schema types.

Type Old Scalar New Scalar
sqa.Date graphene.String graphene.Date
sqa.Time graphene.String graphene.Time
sqa.DateTime graphene.String graphene.DateTime
postgresql.UUID graphene.String graphene.UUID
sqa_utils.UUID --- graphene.UUID
sqa.Variant --- Converts Variant.impl
sqa_utils.IPAddressType --- graphene.String
sqa_utils.EmailType --- graphene.String
sqa_utils.URLType --- graphene.String

Additionally, Enums are now generated from Column.key instead of Column.name. See #301

Other changes

New Contributors

Full Changelog: 3.0.0b1...3.0.0b2