Repository navigation
1.1.0a3 SQLAlchemy integration #1322
KarolJagodzinski
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Ariadne now has a SQLAlchemy integration (and we'd love your feedback)
If you've built a GraphQL API on SQLAlchemy, you've probably written the same resolver about a hundred times. You fetch the model, wire up aiodataloader for
each relationship so the N+1 doesn't murder you, then do it again for the next type. It's not hard. It's just dull.
So we wrote
ariadne.contrib.sqlalchemy. It's shipping as experimental because we genuinely don't know yet which bits of the API are going to feel wrong in real apps, and we'd like to find out before we promise not to change them.There are three pieces:
SQLAlchemyQueryTypehandles root queries. It reads the incoming GraphQL query, sees which fields the client asked for, and picksselectinloadorjoinedloadbased on that.SQLAlchemyObjectTypetakes care of relationship resolvers. When something wasn't eager-loaded, it quietly falls back to a DataLoader instead of firing a query per row.SQLAlchemyDataLoaderExtensionruns aLoaderRegistryper request so you don't have to think about when DataLoaders get created or thrown away.Minimal example
Install
That brings in
SQLAlchemy 2.0+andaiodataloader.Docs
Live here: https://github.com/mirumee/ariadne/blob/orm_shortcut/docs/07-Contrib/02-sqlalchemy.md
If you try it and something annoys you or just behaves weirdly, please open an issue.
All reactions