-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Allow codegen to process multiple query files in a single command #2911
Allow codegen to process multiple query files in a single command #2911
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2911 +/- ##
=======================================
Coverage 96.55% 96.55%
=======================================
Files 468 468
Lines 29201 29265 +64
Branches 3592 3603 +11
=======================================
+ Hits 28194 28257 +63
Misses 827 827
- Partials 180 181 +1 |
Thanks for adding the Here's a preview of the changelog:
Finally, the Here's the preview release card for twitter: Here's the tweet text:
|
Thanks for adding the Here's a preview of the changelog:
Finally, the Here's the preview release card for twitter: Here's the tweet text:
|
f668377
to
aa6a6fc
Compare
tests/cli/test_codegen.py
Outdated
assert " GetUserResult" in path.read_text() | ||
|
||
|
||
def test_codegen_pass_no_query(cli_runner: CliRunner, tmp_path: Path): |
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 don't have an opinion on the proper behavior here. I went with the behavior recommended by click
for variadic arguments
... we believe scripts should gracefully degrade into becoming noops if a variadic argument is empty. The reason for this is that very often, scripts are invoked with wildcard inputs from the command line and they should not error out if the wildcard is empty.
0fbf48d
to
55d6e2d
Compare
strawberry/cli/commands/codegen.py
Outdated
warnings.warn( | ||
"The ConsolePlugin should inherit from ``{__name__}.ConsolePlugin``.", | ||
DeprecationWarning, | ||
stacklevel=1, |
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.
ruff
wants the explicit stacklevel
🤷♂️ .
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.
yeah, that's fine :D
9a4cd6b
to
6811a81
Compare
6811a81
to
d45dc52
Compare
CodSpeed Performance ReportMerging #2911 will not alter performanceComparing Summary
|
@mgilson I'll try to review this during this week 😊 thanks for your patience! |
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.
left some comments, I think this is almost ready to merge :)
strawberry/cli/commands/codegen.py
Outdated
sig = inspect.signature(ptype) | ||
kwargs = {} | ||
if "query" in sig.parameters: | ||
kwargs["query"] = query | ||
if "query_file" in sig.parameters: | ||
kwargs["query_file"] = query | ||
|
||
plugin = ptype(**kwargs) | ||
if not hasattr(plugin, "query"): | ||
plugin.query = query |
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.
is this to keep backwards compatibility?
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.
yeah, I did a lot of shenanigans to try to preserve compatibility with any existing plugins that might be in the wild.
If we don't care about that, then we can probably simplify this a good bit.
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 think it might be fine to break compatibility for this, we can just add a note in our breaking changes files. We could do a codemod too but it is probably not worth doing 😊
strawberry/cli/commands/codegen.py
Outdated
warnings.warn( | ||
"The ConsolePlugin should inherit from ``{__name__}.ConsolePlugin``.", | ||
DeprecationWarning, | ||
stacklevel=1, |
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.
yeah, that's fine :D
strawberry/cli/commands/codegen.py
Outdated
plugins = _load_plugins(selected_plugins, query[0]) | ||
console_plugin = console_plugin_type(query[0], output_dir, plugins) |
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'm not sure I like having to pass the first query here 🤔
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.
Yeah, I dislike this as well. I'd rather have the console_plugin_type
accept a collection of queries, but anyone who has made a custom console plugin type would potentially be broken in that case :(.
b8e4e43
to
f3de817
Compare
strawberry/cli/commands/codegen.py
Outdated
|
||
if TYPE_CHECKING: | ||
from strawberry.codegen import CodegenResult | ||
from pathlib import Path |
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.
AHH!!!
What tool is actually moving this import?
In this case, the tool is thinking that Path
should be in an if TYPE_CHECKING
because it's only used in annotations, however, typer
is introspecting the types so the import statement needs to be present at runtime.
I'm not sure how to prevent our tool from moving this (other than putting in some sort of useless expression that actually uses Path
somewhere).
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.
that's ruff, I think that rule is becoming quite annoying, # noqa: TCH001
should fix it
c6f6d8c
to
7756571
Compare
a89aa95
to
73411da
Compare
@mgilson really sorry for the delay on this :) I think we can merge as it is now, I've changed the plugins to use the filename of the query to generate the files 😊 I think maybe in future we can customise it more to make so that the generated files are generated near the source ones and not passing the output directory at all 😊 let me know if the changes look good to you and I'll merge |
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.
Looks great to me!
…rawberry-graphql#2911) * Add ability for `codegen` to handle multiple input query files. * Add a `RELEASE.md` file. * Update how we name generated files --------- Co-authored-by: Matt Gilson <[email protected]> Co-authored-by: Patrick Arminio <[email protected]>
Description
#2828 hopefully does a good job communicating the use-case for this feature. Currently
codegen
can be very slow if the schema import is an expensive operation. This allows a user to codegen multiple files with a single command (and a single schema import). There are a few minor (backward compatible) extensions to the exposedQueryCodegenPlugin
andConsolePlugin
interfaces. TheRELEASE.md
should describe these changes and the class behaviors in their entirety.Types of Changes
Issues Fixed or Closed by This PR
Checklist