You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(async): add support for async sessions
This PR brings experimental support for async sessions in SQLAlchemyConnectionFields. Batching is not yet supported and will be subject to a later PR.
Co-authored-by: Jendrik <jendrik.joerdening@nooxit.com>
Co-authored-by: Erik Wrede <erikwrede2@gmail.com>
See also: `Graphene Interfaces <https://docs.graphene-python.org/en/latest/types/interfaces/>`_
113
+
114
+
Eager Loading & Using with AsyncSession
115
+
--------------------
116
+
When querying the base type in multi-table inheritance or joined table inheritance, you can only directly refer to polymorphic fields when they are loaded eagerly.
117
+
This restricting is in place because AsyncSessions don't allow implicit async operations such as the loads of the joined tables.
118
+
To load the polymorphic fields eagerly, you can use the `with_polymorphic` attribute of the mapper args in the base model:
119
+
120
+
.. code:: python
121
+
classPerson(Base):
122
+
id= Column(Integer(), primary_key=True)
123
+
type= Column(String())
124
+
name = Column(String())
125
+
birth_date = Column(Date())
126
+
127
+
__tablename__ ="person"
128
+
__mapper_args__ = {
129
+
"polymorphic_on": type,
130
+
"with_polymorphic": "*", # needed for eager loading in async session
131
+
}
132
+
133
+
Alternatively, the specific polymorphic fields can be loaded explicitly in resolvers:
134
+
135
+
.. code:: python
136
+
137
+
classQuery(graphene.ObjectType):
138
+
people = graphene.Field(graphene.List(PersonType))
Dynamic batching of the types based on the query to avoid eager is currently not supported, but could be implemented in a future PR.
144
+
145
+
For more information on loading techniques for polymorphic models, please check out the `SQLAlchemy docs <https://docs.sqlalchemy.org/en/20/orm/queryguide/inheritance.html>`_.
0 commit comments