-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add plugin to reduce client imports #287
Add plugin to reduce client imports #287
Conversation
* Convert input types and return types to `ast.Constant` * Import `TYPE_CHECKING` and import types if set * Import required types inside each method * Add tests * Update CHANGELOG * Update README
e173d8a
to
794743b
Compare
ast.ImportFrom( | ||
module=self.imported_classes[import_class_id], | ||
names=[import_class], | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I developed this plugin outside of ariadne-codegen
so I didn't use any helpers to generate these. Tbh I don't think it helps, it just makes it tricker to read.
Let me know if you'd rather me to import and use all the generators even for plugins or if I can keep this as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just few nits for now.
Co-authored-by: Rafał Pitoń <rafio.xudb@gmail.com>
More nits but I think this will be good to merge after those. |
Co-authored-by: Rafał Pitoń <rafio.xudb@gmail.com>
Co-authored-by: DamianCzajkowski <43958031+DamianCzajkowski@users.noreply.github.com>
0454cce
to
4e06845
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
ast.Constant
TYPE_CHECKING
and import types if setThere are two generated clients to test this with as many permutations as possible both with and without
ShorterResultsPlugin
because it had a major effect on the result (and I had some bugs along the way). However the actual code is contained solely inariadne_codegen/contrib
.This addresses one of the biggest issues from #233. Previously it was very slow to load the
clients.py
because all types used as input and return values were imported. This adds a plugin that converts them toast.Constant
and only imports the types if we're in aTYPE_CHECKING
context.Example from a project with a couple of hundred methods:
Before
After
I wouldn't say it solves the issue because even if this improves imports of the client Pydantic v2 is still very slow. Loading some files with many classes can still take several seconds. I don't think we can solve this without rolling back to Pydantic v1 or wait for an upstream fix though.