prepend api_version to schema#7480
Conversation
| const {api_version: version, type, targeting} = extension.configuration | ||
| const usingTargets = Boolean(targeting?.length) | ||
| const definition = await (usingTargets | ||
| const fetchedDefinition = await (usingTargets |
There was a problem hiding this comment.
I dont understand the difference between definition and fetched_definition, what if we keep this definition and call the other definition_with_version or something?
There was a problem hiding this comment.
definition is essentially what was here before, the contents we're about to write to the local schema.
I introduced fetchedDefinition to name the intermediate value: the raw schema we just grabbed from the server, before the prepending step.
Reading top-down: fetch -> add version header -> write.
Whereas before it was just fetch -> write.
Open to renaming if it still reads confusingly, but it felt clearer to me separated.
There was a problem hiding this comment.
Yeah I guess fetched_definition doesn't immediately make sense to me when I read the code but its okay, its just a variable name, I won't let it block you from shipping the PR.
d672631 to
5f79c3a
Compare
saga-dasgupta
left a comment
There was a problem hiding this comment.
Was able to tophat it works as expected.
|
/snapit |
|
🫰✨ Thanks @gonzaloriestra! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260513114658Caution After installing, validate the version by running |
| outputContent`The ${outputToken.cyan( | ||
| 'schema.graphql', | ||
| )} file for ${outputToken.yellow(localIdentifier)} was generated for api_version ${outputToken.yellow( | ||
| versionFromSchema, | ||
| )} but your function is now on api_version ${outputToken.yellow(apiVersion)}.`, |
There was a problem hiding this comment.
Maybe it's something we can ask to UX, but I think it's better to just use outputToken.genericShellCommand instead of custom colors for consistency.
There was a problem hiding this comment.
Hmmmm, I went back and forth on this.
A couple of reasons I'd lean toward keeping raw color tokens here rather than genericShellCommand:
genericShellCommandrenders as bright magenta in backticks and is used across the codebase exclusively for actual commands (including theshopify app function schematoken on the very next line).- Raw colors are the prevailing pattern for highlighting tokens — including inside
services/function/(build.tsusesyellow/greenin anAbortError,info.tsusescyanfor a function target).
That said, your comment made me notice the message had three concepts but only two colors. localIdentifier was sharing yellow with the two version strings. I've tweaked it so the two "named things" (filename + function name) are both cyan, and yellow is reserved for the mismatched versions, which I think improves the readability.
5f79c3a to
f80f6ea
Compare
WHY are these changes introduced?
Part of https://github.com/shop/issues-shopifyvm/issues/945
When a developer bumps
api_versionin a function'sshopify.extension.toml, the on-diskschema.graphqlbecomes stale. The nextshopify app function buildthen fails with crypticgraphql-code-generatorerrors like:…with no indication that the underlying problem is a stale schema that just needs to be re-fetched. Today the build path is fully local — it never consults
api_versionandschema.graphqlcarries no version metadata, so staleness is undetectable.The error surfaced gives them no actionable hint pointing at
shopify app function schema.WHAT is this pull request doing?
Stamps the
api_versionintoschema.graphqlwhenshopify app function schemawrites it, then validates that marker against the extension's TOML at the start of everyshopify app function build. When they disagree, the build aborts up-front with an actionable message instead of letting codegen fail mysteriously.New file
packages/app/src/cli/services/function/schema-version.ts— self-contained helpers:prependSchemaVersionHeader(definition, version)— adds a# api_version: <ver>marker line to the top of the SDL.readSchemaApiVersion(path)— scans the leading comment block for the marker; returnsundefinedfor missing files or legacy schemas (no marker).validateSchemaApiVersion({directory, localIdentifier, apiVersion})— throws anAbortErrorwith remediation when the on-disk marker disagrees with the configuredapi_version.Modified files
services/generate-schema.ts—shopify app function schemanow writes the marker as the first line of the SDL (both file and stdout output).services/build/extension.ts—buildFunctionExtensioninvokesvalidateSchemaApiVersiononce, up-front, before any function build work (typegen, esbuild, javy, wasm-opt, trampoline).Behavior
shopify app function schema).The schema header is a single line:
How to test your changes?
api_version = "2025-07"in the function'sshopify.extension.toml.schema.graphqlnow starts with# api_version: 2025-07.api_versionto"2025-10"in the TOML.shopify app function schema.schema.graphql(simulate an older fetched file). The build command should behave exactly as it did before this change (no false-positive abort).Post-release steps
N/A.
Checklist
patchfor bug fixes ·minorfor new features ·majorfor breaking changes) and added a changeset withpnpm changeset add