MyGit

3.0.0b2

graphql-python/graphene-sqlalchemy

版本发布时间: 2022-07-15 17:35:05

graphql-python/graphene-sqlalchemy最新发布版本:v3.0.0rc1(2023-12-05 05:43:04)

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!

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.

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: https://github.com/graphql-python/graphene-sqlalchemy/compare/3.0.0b1...3.0.0b2

相关地址:原始地址 下载(tar) 下载(zip)

查看:2022-07-15发行的版本