fix: support graphql v17 (directives can be undefined) - #214
Open
jarkko wants to merge 1 commit into
Open
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.
Summary
Adds support for
graphqlv17 by fixing a crash that occurs during code generation, and widens thegraphqlpeer dependency range to accept^17.0.0.The problem
In graphql-js 17, AST definition nodes no longer default their
directivesfield to an empty array. When a type declares no directives,directivesis nowundefinedinstead of the[]that graphql-js 16 always produced.The plugin detects the
@oneOfdirective by calling.some(...)directly onnode.directives, which throws under graphql 17 when a type has no directives:This crashes codegen at the
InputObjectTypeDefinitionvisitor for any input type without directives (i.e. the common case), making the plugin unusable with graphql 17.The fix
Use optional chaining at the two
@oneOfdetection sites insrc/index.tsso a missingdirectivesarray is treated as "no directives" rather than crashing:InputObjectTypeDefinitionvisitor that collects@oneOfinput typeshasOneOfDirectiveBoth changes are backward compatible: on graphql 14–16
directivesis still[], so?.some(...)behaves exactly as before.Also widens the
graphqlpeer dependency range to^14.6.0 || ^15.0.0 || ^16.0.0 || ^17.0.0.Testing
pnpm buildpassespnpm testpasses (all existing tests/snapshots green)eslintandtsc --noEmitcleanI kept this focused on the fix + peer range rather than adding a regression test: the existing suite builds schemas via graphql 16's
buildSchema, which always populatesdirectives: [], so theundefinedcase cannot be reproduced without bumping the project'sgraphqldevDependency to 17 (which would churn the snapshot suite) or hand-constructing an AST. Happy to add a test in whatever form you'd prefer if you'd like one.