-
Notifications
You must be signed in to change notification settings - Fork 7
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
Use graphql_client_codegen with output query string #51
Conversation
3758f94
to
8642e38
Compare
6faed75
to
d92765a
Compare
)?; | ||
let expected = crate::target_a::output::FunctionTargetAResult { status: Some(200) }; |
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.
📝 Alternative to changing these tests to assert JSON output is to make this result type public.
Error:
d@Delta-Shopify shopify-function-rust % cargo t
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
Compiling shopify_function_macro v0.5.0 (/Users/d/src/github.com/Shopify/shopify-function-rust/shopify_function_macro)
Compiling shopify_function v0.5.0 (/Users/d/src/github.com/Shopify/shopify-function-rust/shopify_function)
Compiling example_with_targets v1.0.0 (/Users/d/src/github.com/Shopify/shopify-function-rust/example_with_targets)
Compiling example v1.0.0 (/Users/d/src/github.com/Shopify/shopify-function-rust/example)
error[E0603]: module `output` is private
--> example_with_targets/src/tests.rs:16:37
|
16 | let expected = crate::target_a::output::FunctionTargetAResult { status: Some(200) };
| ^^^^^^ --------------------- struct `FunctionTargetAResult` is not publicly re-exported
| |
| private module
|
note: the module `output` is defined here
--> example_with_targets/src/lib.rs:4:1
|
4 | / #[shopify_function_target(
5 | | // Implicit target = "example.target-a"
6 | | // Implicit generated module name = "target_a"
7 | | query_path = "a.graphql",
8 | | schema_path = "schema.graphql"
9 | | )]
| |__^
= note: this error originates in the attribute macro `shopify_function_target` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0603]: module `output` is private
--> example_with_targets/src/tests.rs:32:34
|
32 | let expected = crate::mod_b::output::FunctionTargetBResult {
| ^^^^^^ --------------------- struct `FunctionTargetBResult` is not publicly re-exported
| |
| private module
|
note: the module `output` is defined here
--> example_with_targets/src/lib.rs:16:1
|
16 | / #[shopify_function_target(
17 | | // Explicit target if function name does not match target handle
18 | | target = "example.target-b",
19 | | // Override generated module name
... |
22 | | schema_path = "schema.graphql"
23 | | )]
| |__^
= note: this error originates in the attribute macro `shopify_function_target` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0603`.
error: could not compile `example_with_targets` (lib test) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
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.
Maybe export a test helper function to assert expected JSON string?
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.
What are the reasons not to make it public?
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.
Good question. I could do that 😆
|
||
## Usage | ||
|
||
* The [`generate_types`] macro allows you to generate structs based on your [input query]. It will also generate output/response types for the current Function API, based on the provided schema. | ||
* It will automatically generate an `.output.graphql` file for code generation purposes. This file can be added to your `.gitignore`. |
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.
This is the relevant non-formatting change in the file.
d92765a
to
26e0ca4
Compare
26e0ca4
to
126105f
Compare
126105f
to
2402d95
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.
Nice job. No more temporary, hidden files 🎉
414adaf
to
46dd55b
Compare
"Output", | ||
&output_query_file_name, | ||
schema_path.value().as_str(), | ||
extern_enums.as_deref(), |
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.
@jbourassa Does the output struct need extern enums as well?
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.
Ideally, yes: if the output struct wants e.g. CountryCode
, we don't want to bloat the binary size and have mismatching definitions for CountryCode
.
46dd55b
to
21de3ec
Compare
129ba9b
to
307b0ee
Compare
)?; | ||
let expected = crate::target_a::output::FunctionTargetAResult { status: Some(200) }; |
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.
What are the reasons not to make it public?
/// | ||
/// Note: This macro creates a file called `.output.graphql` in the root | ||
/// directory of the project. It can be safely added to your `.gitignore`. We | ||
/// hope we can avoid creating this file at some point in the future. |
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.
🎉
For the sake of time I'm going to merge this and file an issue to consider making the output structs public if someone else wants to do it 😆 |
Closes https://github.com/Shopify/script-service/issues/7474
generate_types
andshopify_function_target
macros:pub struct Output
usinggraphql_client_codegen::generate_module_token_stream_from_string
using the output query string, instead of writing the query to a temporary.output.graphql
filepub struct Input
usinggraphql_client_codegen::generate_module_token_stream
as it's still using a file pathNo change to the interface, internally doesn't require the
.output.graphql
file anymore.Depends on
graphql_client_codegen
version