3.0.0b2
版本发布时间: 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!
- Support setting @hybrid_property's return type from the functions type annotations. by @flipbit03 in https://github.com/graphql-python/graphene-sqlalchemy/pull/340
- Supplant @hybrid_property's type annotation support with
Optional[T]
by @flipbit03 in https://github.com/graphql-python/graphene-sqlalchemy/pull/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 https://github.com/graphql-python/graphene-sqlalchemy/pull/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
- Native support for additional Type Converters by @erikwrede in https://github.com/graphql-python/graphene-sqlalchemy/pull/353
Other changes
- Build clean up by @mvanlonden in https://github.com/graphql-python/graphene-sqlalchemy/pull/318
- I resolved spelling and capitalization mistakes in the file,
README.md
. by @quinnkj in https://github.com/graphql-python/graphene-sqlalchemy/pull/290 - Fix for import from graphql-relay-py (#329) by @Cito in https://github.com/graphql-python/graphene-sqlalchemy/pull/330
- Fix for issue graphql-python/graphene-sqlalchemy#288 by @jbeard4 in https://github.com/graphql-python/graphene-sqlalchemy/pull/289
- Don't suppress SQLAlchemy errors when mapping classes by @connorbrinton in https://github.com/graphql-python/graphene-sqlalchemy/pull/169
- Pick up the docstrings of hybrid properties by @bim9262 in https://github.com/graphql-python/graphene-sqlalchemy/pull/344
- Add Python 3.10 Support & update pre-commit hooks by @erikwrede in https://github.com/graphql-python/graphene-sqlalchemy/pull/352
New Contributors
- @quinnkj made their first contribution in https://github.com/graphql-python/graphene-sqlalchemy/pull/290
- @jbeard4 made their first contribution in https://github.com/graphql-python/graphene-sqlalchemy/pull/289
- @connorbrinton made their first contribution in https://github.com/graphql-python/graphene-sqlalchemy/pull/169
- @flipbit03 made their first contribution in https://github.com/graphql-python/graphene-sqlalchemy/pull/340
- @bim9262 made their first contribution in https://github.com/graphql-python/graphene-sqlalchemy/pull/344
Full Changelog: https://github.com/graphql-python/graphene-sqlalchemy/compare/3.0.0b1...3.0.0b2