Skip to content

Type a prepare result's variables with its run query's variables type - #141

Closed
saga-dasgupta wants to merge 2 commits into
saga/custom-scalar-overridesfrom
saga/prepare-variables-types
Closed

saga-dasgupta wants to merge 2 commits into
saga/custom-scalar-overridesfrom
saga/prepare-variables-types

Conversation

@saga-dasgupta

Copy link
Copy Markdown
Contributor

Stacked on #140.

Why

With #140, a prepare target's mismatched variables fail the build. Editors still can't show the mistake while you write it, because the generated type for the prepare result's variables is unknown.

What

typegen.js gives each prepare result's variables its run query's variables type. The prepare target's existing return type then lets editors underline unknown, missing and mistyped variables as you type. It's the editor side of Shopify/shopify-function-rust#252.

To do this, it adds @shopify/shopify_function/codegen, which typegen.js uses in place of the typescript plugin. It generates the same types, and takes customScalarOverrides to give a custom scalar field of an input object another type. Lists, nullability and oneOf variants are kept, and it can also be used when running codegen yourself.

Tested

…query

Add typegen.js, which Shopify CLI runs instead of graphql-code-generator
when this package has it (Shopify/cli#8829). It generates the function's
types with the codegen plugins this package depends on, whatever the app's
package manager hoists. It then exits non-zero, failing the build, when a
prepare target returns variables its run query doesn't accept.

The check is moved here from Shopify/cli#8829: it follows what the prepare
export returns, ignoring type annotations and casts, and validates it
against the run query's variable definitions.
Add @shopify/shopify_function/codegen, a plugin to use instead of
typescript, with the same output. It takes customScalarOverrides to give a
custom scalar field of an input object another type. typegen.js uses it in
place of typescript, and gives each prepare result's variables its run
query's variables type, so editors report mismatches.
@saga-dasgupta

Copy link
Copy Markdown
Contributor Author

Closing for now: #140 switched to a build check instead of taking over typegen, so this no longer applies on top of it. The branch stays, for when we choose how to deliver editor types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant