Repository navigation
fix(website): patch typescript-json-schema for graphql-js v17 index signatures - #11036
Open
BuddhaBing wants to merge 1 commit into
Open
BuddhaBing wants to merge 1 commit into
BuddhaBing wants to merge 1 commit into
Conversation
…ignatures
The website `generate-config-schema` script crashes under graphql-js
v17 with:
Error: Not supported: IndexSignatureDeclaration with index symbol
other than a number or a string
`Types.Schema` (packages/utils/plugins-helpers) unions in `GraphQLSchema`,
so the generator walks into graphql-js's own types. In v17,
`GraphQLSchemaExtensions` changed its index signature from
`[attributeName: string]` to `[attributeName: string | symbol]`, and
typescript-json-schema only accepts a pure `string` or `number` index
key, so it throws.
Upstream has not fixed this (0.68.0 has identical logic), so this patches
typescript-json-schema via pnpm `patchedDependencies` (same mechanism
already used for bob-the-bundler) to treat a union index key made of
string/symbol constituents as a normal string-indexed object.
`GraphQLSchemaExtensions` then serializes as
`{ "type": "object", "additionalProperties": {} }`, which is correct.
config.schema.json is regenerated: the diff is confined entirely to
graphql-internal types reachable from `GraphQLSchema`; every plugin and
preset config definition is unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
This branch has not been deployed
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.
What
Patches
typescript-json-schema(via pnpmpatchedDependencies) so thatpnpm --filter website generate-config-schemaworks under graphql-js v17, and regenerateswebsite/config.schema.json.Why
After the bump to
graphql@17, the website script that generates the JSON Schema forcodegen.ts/codegen.ymlcrashes:Root cause
generate-config-schema.tswalksTypes.Configto build the schema. The chain to the crash is:Types.Config.schemaisInstanceOrArray<Types.Schema>, andTypes.Schemais a union that ends in| GraphQLSchema(packages/utils/plugins-helpers/src/types.ts).The generator therefore descends into graphql-js's own
GraphQLSchematype → itsextensionsproperty → theGraphQLSchemaExtensionsinterface.In graphql-js v17, that interface changed its index signature:
typescript-json-schemaonly supports a purestringornumberindex key. It checksindexType.flags === ts.TypeFlags.Stringwith strict equality, so the union keystring | symbol(aUniontype) fails the check and it throws.This is not a bug in this repo's script or types — it's an incompatibility between graphql-js v17's type definitions and
typescript-json-schema. Upstream has not fixed it:typescript-json-schema@0.68.0contains byte-for-byte the same check, so a version bump does not help.The fix
A one-line change to
typescript-json-schema'sisIndexedObjectcheck, applied through pnpmpatchedDependencies(the same mechanism already used in this repo forbob-the-bundler):A union index key whose constituents are all string/symbol is now treated as a normal string-indexed object.
GraphQLSchemaExtensionsthen serializes correctly as:This also generalises to graphql-js's other
*Extensionsinterfaces, which moved to the samestring | symbolindex signature in v17.About the regenerated
config.schema.jsonThe schema is regenerated as part of this PR. The diff is entirely confined to graphql-internal types reachable from
GraphQLSchema(its internals plus the AST-node graph —DocumentNode,FieldNode,GraphQLError, etc.). Every plugin and preset config definition is unchanged — all hunks fall at/after theGraphQLSchemadefinition; nothing above it (Types.Config, every*PluginConfig, every preset,GeneratedPluginsMap) is touched. The net line reduction reflects graphql-js v17 restructuring its own types, not any loss of plugin/preset config coverage. These graphql-internal definitions are effectively inert in a config JSON Schema anyway, since a liveGraphQLSchemaobject cannot be expressed in YAML/JSON config.Alternative considered: patch the script instead of the dependency
Rather than patching
typescript-json-schema, we could keepGraphQLSchemaout of the walked type graph entirely — for example, by post-processing ingenerate-config-schema.tsto replace theGraphQLSchemabranch of theTypes.Schemaunion with an opaque{}/object, so the generator never descends into graphql-js internals.Pros: no dependency patch to carry across future
typescript-json-schemabumps; removes a large block of inert graphql-internal noise fromconfig.schema.json.Cons:
typescript-json-schemahas no clean "exclude this type" hook, so it's more code and more fragile than the one-line patch; and the only alternative place to cut the union — editingTypes.Schemainplugins-helpers— would change a real, published runtime type purely to satisfy a docs-tooling build, which is undesirable. Editinggenerate-config-schema.tsto prune the branch after the fact is viable but still more involved than the patch.The dependency patch was chosen as the smallest, most robust change with the least blast radius. The script-level prune would make a reasonable follow-up if maintainers would prefer to drop the graphql-internal types from the schema altogether — happy to switch approaches if preferred.
Notes
typescript-json-schemais a dev-only dependency of thewebsiteworkspace and is not used anywhere else in the monorepo, so this affects only the docs schema-generation build — no published package or runtime codegen behaviour changes.🤖 Generated with Claude Code