Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom media types (HTTP Content-Type) for the normal request processor #3217

Open
laurisvan opened this issue Mar 31, 2024 · 2 comments

Comments

@laurisvan
Copy link

Is your feature request related to a problem? Please describe.

Our GraphQL API uses Content-Type for versioning, e.g. the client requests 'application/rescomms-0.11.0+json' (or a few API versions), and when the API has been bumped to e.g. application/rescomms-0.12.0+json, the server will reply with 406. I noticed GraphQL Yoga uses 'application/graphql-response+json', which is referred to in useResultProcessors and processRegularResult.

While it might be possible to create a totally custom result processor, we believe the default request processor would be fine for our use. Would it perhaps be possible to override the default 'application/graphql-response+json' with a custom result that useResultProcessors and processRegularResult uses?

Describe the solution you'd like

Provide default media types through Yoga constructors, and these would be used in place of with hard-coded defaults, e.g.

const yoga = createYoga({ mediaTypes: ['application/json', 'application/rescomms-0.11.0+json'] })

Describe alternatives you've considered

I believe an alternative to this would be a custom request processor, yet I did not manage to write one yet. It seems the helpers for e.g. stringifying JSON, error handling etc. were out of reach, as they were not part of public API.

Additional context

@ardatan
Copy link
Collaborator

ardatan commented Mar 31, 2024

https://github.com/dotansimha/graphql-yoga/pull/3219/files
I created an example for you. But later, I guess we should document it.

@laurisvan
Copy link
Author

@ardatan Thanks, this works like charm (yet the list on accepted content types is wrong in regular.js in case of content type failure). My migration to yoga (from fastify + graphql-helix) is not yet complete, but I believe this will work.

In order to include processRegularResult, I needed to patch the index files to export - that will likely be needed in order the example to be usable.

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

No branches or pull requests

2 participants