Skip to content

Fix crash on invalid directive locations in playground#231

Closed
captbaritone wants to merge 1 commit into
mainfrom
directive-location-bug
Closed

Fix crash on invalid directive locations in playground#231
captbaritone wants to merge 1 commit into
mainfrom
directive-location-bug

Conversation

@captbaritone
Copy link
Copy Markdown
Owner

Summary

  • The playground crashed with an unhandled GraphQLError when using invalid directive locations like DIRECTIVE_DEFINITION, because instanceof GraphQLError failed in the bundled environment (duplicate module instances)
  • Replaced parser.parseDirectiveLocation() with manual parseName() + validation against the DirectiveLocation enum, and switched to err.name === "GraphQLError" check for robustness
  • Added a better error message listing all valid directive locations

Test plan

  • Added test fixture directiveOnDirectiveDefinitionLocation.invalid.ts
  • Updated existing defineCustomDirectiveLocationInvalid snapshot with improved error message
  • All tests pass
  • Verified fix in local playground

🤖 Generated with Claude Code

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 18, 2026

Deploy Preview for grats canceled.

Name Link
🔨 Latest commit 95640fa
🔍 Latest deploy log https://app.netlify.com/projects/grats/deploys/69e2cd2e6a7fed0008136093

The playground crashed with an unhandled GraphQLError when using invalid
directive locations like `DIRECTIVE_DEFINITION`. This happened because
`instanceof GraphQLError` failed in the bundled environment due to
duplicate module instances.

Fix by replacing `parser.parseDirectiveLocation()` with `parseName()`
and validating against the DirectiveLocation enum after parsing. Also
use `err.name === "GraphQLError"` instead of `instanceof` for
robustness in bundled environments.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@captbaritone captbaritone force-pushed the directive-location-bug branch from 9985342 to 95640fa Compare April 18, 2026 00:15
@captbaritone
Copy link
Copy Markdown
Owner Author

Replaced by #232

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