Repository navigation
Generate typed prepare variables from run queries - #138
Closed
saga-dasgupta wants to merge 1 commit into
Closed
saga-dasgupta wants to merge 1 commit into
saga-dasgupta wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A prepare target returns variables for its run target's input query as untyped JSON. The generated prepare result therefore doesn't catch a misspelled key, missing required variable, or incompatible value.
This explores the type-generation approach from Shopify/shopify-function-rust#252 for JavaScript functions.
What
Adds an opt-in
@shopify/shopify_function/prepare-variables.cjscodegen plugin with explicit schema-field → named-query mappings:{ "prepareVariables": { "CartValidationsGeneratePrepareResult.variables": "CartValidationsGenerateRun" } }The plugin replaces both
typescriptandtypescript-operationsfor the output. It composes those generators, types only the mapped JSON result fields with the matching query's variables type, and preserves unrelated JSON fields. GraphQL Codegen 6's operations generator emits its own used input-object and enum declarations, so overlapping schema declarations and repeated custom-scalar imports are reconciled.Includes:
Scope and limitations
checkJs, and null checking needsstrictNullChecks.JSONorJSON!on object types and reference named query operations included in codegen's documents.globalNamespace,noExport,onlyEnums, andonlyOperationTypesare not supported.