Skip to content

Send spec-compliant Accept header in fetchers#4199

Draft
trevor-scheer wants to merge 3 commits intomainfrom
trevor/fetcher-spec-accept-header
Draft

Send spec-compliant Accept header in fetchers#4199
trevor-scheer wants to merge 3 commits intomainfrom
trevor/fetcher-spec-accept-header

Conversation

@trevor-scheer
Copy link
Copy Markdown
Contributor

Summary

  • Send application/graphql-response+json as the preferred content type per the GraphQL over HTTP spec, falling back to application/json;q=0.9
  • Applied to both createSimpleFetcher (which previously sent no Accept header) and createMultipartFetcher (which sent application/json, multipart/mixed)

Closes #4189

Changes

  • createSimpleFetcher: added accept: 'application/graphql-response+json, application/json;q=0.9'
  • createMultipartFetcher: changed accept from application/json, multipart/mixed to application/graphql-response+json, application/json;q=0.9, multipart/mixed
  • Both fetchers continue to allow user-provided headers (options.headers, fetcherOpts.headers) to override the default
  • Added acceptHeaders.spec.ts with tests covering default headers and override behavior

Validation Steps

  1. yarn dev:graphiql to start the dev server
  2. Open GraphiQL in the browser and run a query (e.g. { __typename })
  3. In DevTools Network tab, inspect the fetch request to the GraphQL endpoint — the Accept request header should be application/graphql-response+json, application/json;q=0.9, multipart/mixed

Add `application/graphql-response+json` as the preferred content type
per the GraphQL over HTTP spec, with `application/json` as a fallback.
Applied to both createSimpleFetcher and createMultipartFetcher.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 18, 2026

🦋 Changeset detected

Latest commit: bceaa66

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

This PR includes changesets to release 3 packages
Name Type
@graphiql/toolkit Minor
@graphiql/plugin-history Patch
@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

@github-actions
Copy link
Copy Markdown
Contributor

The latest changes of this PR are not available as canary, since there are no linked changesets for this PR.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.96%. Comparing base (7979bf5) to head (bceaa66).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4199   +/-   ##
=======================================
  Coverage   63.96%   63.96%           
=======================================
  Files          35       35           
  Lines        3086     3086           
  Branches      934      934           
=======================================
  Hits         1974     1974           
  Misses       1107     1107           
  Partials        5        5           

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TallTed
Copy link
Copy Markdown
Contributor

TallTed commented Apr 20, 2026

The currently specified Accept: header —

application/graphql-response+json, application/json;q=0.9, multipart/mixed

— persists an error. Leaving off the quality rating causes a media type to be treates as if 1.0 (maximum) quality, and that's what the old Accept: header had, and what the new header persists.

I'm fairly well certain that one of application/graphql-response+json or multipart/mixed is really preferred over the other, but I'm not sure which that is.

For sake of understanding, I offer two options. The first prefers application/graphql-response+json and the second prefers multipart/mixed.

application/graphql-response+json, application/json;q=0.9, multipart/mixed;q=0.95

application/graphql-response+json;q=0.95, application/json;q=0.9, multipart/mixed

Note — both of my offered options presume that application/json is the least-preferred. I hope that what I've written is clear enough that any reader of this comment can figure out how to make application/json more preferred than either of the other two.


const SPEC_ACCEPT = 'application/graphql-response+json, application/json;q=0.9';
const MULTIPART_ACCEPT = `${SPEC_ACCEPT}, multipart/mixed`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const QUERY = '{ __typename }';
const BASE_URL = 'http://localhost';

I don't want to be annoying, but these vars are repeated 5 times each 😄

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.

[graphiql] Send Accept: application/graphql-response+json, application/json;q=0.9

3 participants