Skip to content

fix(graphiql-react): plain-language message with line and column for invalid JSON - #4557

Merged
trevor-scheer merged 1 commit into
graphql:mainfrom
vishwakt:fix/friendly-jsonc-parse-errors
Sep 26, 2026
Merged

trevor-scheer merged 1 commit into
graphql:mainfrom
vishwakt:fix/friendly-jsonc-parse-errors

Conversation

@vishwakt

Copy link
Copy Markdown
Contributor

Summary

When the Variables or Headers pane contains invalid JSON, run() parses it client-side and writes an error into the response pane without sending a request. That error showed the bare jsonc-parser error code, in the same shape and place as a real server response:

{ "errors": [{ "message": "Variables are invalid JSON: ValueExpected." }] }

This makes the message readable and clearly client-side:

{ "errors": [{ "message": "Request not sent. Variables are invalid JSON: expected a value at line 1, column 8." }] }

Refs #4501. This addresses the unfriendly message and the "looks like a server response" confusion from that issue. The request for a customization hook (a prop, callback, or plugin hook) is a public API decision, so it is intentionally left for maintainers to discuss on the issue.

Changes

  • utility/jsonc.ts: map jsonc-parser error codes to plain-language descriptions and include the line and column derived from the reported offset. Multiple errors are still listed together.
  • stores/execution.ts: prefix the client-side validation error with Request not sent.
  • Add utility/jsonc.spec.ts covering the message format, line/column on multi-line input, multiple errors, and that valid JSONC (comments, trailing commas) still parses.

How to verify

In the netlify preview (or a local GraphiQL):

  1. Query: query Q($id: Int!) { node(id: $id) { id } }
  2. Variables pane: {"id": }
  3. Press Run.

Before: the response pane shows Variables are invalid JSON: ValueExpected. and it is not obvious that no request was made.
After: it shows Request not sent. Variables are invalid JSON: expected a value at line 1, column 8. and no request is sent.

The same applies to the Headers pane, and to multi-line input, where the line and column point at the offending token.

Credit

Thanks to @limarkxx for the clear report, including pinpointing the exact code path.

…invalid JSON

When the Variables or Headers pane contains invalid JSON, the response pane
showed the bare jsonc-parser error code (e.g. "Variables are invalid JSON:
ValueExpected.") in the same shape and place as a server response.

Map jsonc-parser error codes to plain-language descriptions and include the
line and column derived from the reported offset, e.g. "expected a value at
line 1, column 8". Prefix the message with "Request not sent." so it is not
mistaken for a server response. Add unit tests for the JSONC parsing utility.

Refs graphql#4501.
@changeset-bot

changeset-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1429549

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphiql/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@trevor-scheer
trevor-scheer merged commit 9d9790d into graphql:main Sep 26, 2026
14 checks passed
trevor-scheer pushed a commit that referenced this pull request Sep 28, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to graphiql-6, this
PR will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`graphiql-6` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `graphiql-6`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## graphiql@6.0.0-beta.3

### Minor Changes

- [#4589](#4589)
[`7f9e0cc`](7f9e0cc)
Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Export the
immutable `DEFAULT_PLUGINS` array and the default Query Builder and
Collections plugin constants. Customize GraphiQL's defaults without
importing its plugin packages directly.

### Patch Changes

- [#4570](#4570)
[`c7d5295`](c7d5295)
Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Export
`COLLECTIONS_PLUGIN` for the default collections configuration. Use
`collectionsPlugin(options)` when you need custom storage or
permissions.

- Updated dependencies
[[`c7d5295`](c7d5295),
[`9d9790d`](9d9790d)]:
  - @graphiql/plugin-collections@1.0.0-beta.3
  - @graphiql/react@1.0.0-beta.3
  - @graphiql/plugin-doc-explorer@1.0.0-beta.3
  - @graphiql/plugin-history@1.0.0-beta.3
  - @graphiql/plugin-query-builder@1.0.0-beta.3
## @graphiql/plugin-collections@1.0.0-beta.3

### Minor Changes

- [#4570](#4570)
[`c7d5295`](c7d5295)
Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Export
`COLLECTIONS_PLUGIN` for the default collections configuration. Use
`collectionsPlugin(options)` when you need custom storage or
permissions.

### Patch Changes

- Updated dependencies
[[`9d9790d`](9d9790d)]:
  - @graphiql/react@1.0.0-beta.3
## cm6-graphql@1.0.0-beta.1

### Patch Changes

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
## codemirror-graphql@3.0.0-beta.1

### Patch Changes

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
## @graphiql/plugin-code-exporter@6.0.0-beta.3

### Patch Changes

- Updated dependencies
[[`9d9790d`](9d9790d)]:
  - @graphiql/react@1.0.0-beta.3
## @graphiql/plugin-doc-explorer@1.0.0-beta.3

### Patch Changes

- Updated dependencies
[[`9d9790d`](9d9790d)]:
  - @graphiql/react@1.0.0-beta.3
## @graphiql/plugin-history@1.0.0-beta.3

### Patch Changes

- Updated dependencies
[[`9d9790d`](9d9790d)]:
  - @graphiql/react@1.0.0-beta.3
## @graphiql/plugin-query-builder@1.0.0-beta.3

### Patch Changes

- Updated dependencies
[[`9d9790d`](9d9790d)]:
  - @graphiql/react@1.0.0-beta.3
## @graphiql/react@1.0.0-beta.3

### Patch Changes

- [#4557](#4557)
[`9d9790d`](9d9790d)
Thanks [@vishwakt](https://github.com/vishwakt)! - Improve the error
shown when the Variables or Headers pane contains invalid JSON. The
message now uses plain language with a line and column (for example
`expected a value at line 1, column 8`) instead of the bare
`jsonc-parser` error code (`ValueExpected`), and is prefixed with
`Request not sent.` so it is not mistaken for a server response.

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
  - monaco-graphql@2.0.0-beta.1
## graphql-language-service@6.0.0-beta.1

### Patch Changes

- [#4590](#4590)
[`5affc68`](5affc68)
Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Remove the
CommonJS-only `nullthrows` dependency and replace `picomatch-browser`
with an ESM-compatible glob matcher.
## graphql-language-service-cli@4.0.0-beta.1

### Patch Changes

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
  - graphql-language-service-server@3.0.0-beta.1
## graphql-language-service-server@3.0.0-beta.1

### Patch Changes

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
## monaco-graphql@2.0.0-beta.1

### Patch Changes

- [#4590](#4590)
[`5affc68`](5affc68)
Thanks [@trevor-scheer](https://github.com/trevor-scheer)! - Remove the
CommonJS-only `nullthrows` dependency and replace `picomatch-browser`
with an ESM-compatible glob matcher.

- Updated dependencies
[[`5affc68`](5affc68)]:
  - graphql-language-service@6.0.0-beta.1
## vscode-graphql@1.0.0-beta.1

### Patch Changes

- Updated dependencies []:
  - graphql-language-service-server@3.0.0-beta.1

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
trevor-scheer added a commit that referenced this pull request Sep 29, 2026
After #4557 added a changeset, the Release job's `pnpm ci:version` path
ran a non-frozen install and then failed type checking
`@graphiql/plugin-doc-explorer`
([run](https://github.com/graphql/graphiql/actions/runs/36252528615)).
pnpm linked `@testing-library/jest-dom` to Vitest 4.1.6 while the tests
import Vitest 4.1.11, so its matcher augmentation no longer applied.

`@vitest/web-worker@4.1.6` declares an exact `vitest: 4.1.6` peer. This
pins the root `vitest` and all four `@vitest/web-worker` declarations to
4.1.11 and updates the lockfile, keeping the peer and test imports on
the same types after the release install.

The repo also used `latest` for `oxlint-tsgolint`, which made `pnpm
dedupe --check` depend on the registry's current release. The last two
commits update it from 7.0.2001 to 7.0.2003 and pin that version.
trevor-scheer pushed a commit that referenced this pull request Sep 30, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @graphiql/react@0.39.1

### Patch Changes

- [#4557](#4557)
[`9d9790d`](9d9790d)
Thanks [@vishwakt](https://github.com/vishwakt)! - Improve the error
shown when the Variables or Headers pane contains invalid JSON. The
message now uses plain language with a line and column (for example
`expected a value at line 1, column 8`) instead of the bare
`jsonc-parser` error code (`ValueExpected`), and is prefixed with
`Request not sent.` so it is not mistaken for a server response.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants