Skip to content

Conversation

@phryneas
Copy link
Contributor

This would add support for the GraphQL over HTTP spec: https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#accept

The spec introduces a new mime type that future severs should be able to handle - 'application/graphql-response+json' instead of the traditional 'application/json'.

So right now, all tests using HttpResponse.json would need to switch over to a new constructing function.
My suggestion here would be to just have GraphQLHandler return based on a list of supportedMimeTypes and the priority specified by the GraphQL client.
Clients requesting 'application/json' would be served 'application/json' while clients requesting "application/graphql-response+json, application/json;q=0.9" would be served 'application/graphql-response+json'.

Note that it would be possible to still always return 'application/json' and simulate a server that only speaks the old protocol by specifying a supportedMimeTypes of ['application/json'].

This is still lacking tests, but there is a good chance you want completely different behaviour so I'm opening this as-is for discussion.

'application/json',
]

const wrappedResolver: typeof resolver = (info) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sure there's a more elegant way to do this that I'm just not aware of....

@kettanaito
Copy link
Member

Hi, @phryneas. Thanks for opening this!

It would help a lot if we started from the intended usage experience. How do you see people using MSW to mock queries done via the GraphQL-over-HTTP spec? Let's design the ideal usage and then work down from there to see what implementation that would require.

From my limited understanding, all that should happen is that mocked responses from graphql.* handlers should now contain the content-type: application/graphql-response+json header. Does anything else change for the developer who wishes to mock that standard?

@kettanaito kettanaito changed the title feat(graphq): add support for graphql-over-http spec feat(GraphQL): support application/graphql-response+json requests Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants