Closed chinmayghotkar closed 1 year ago
This seems like it might be an issue with the main @apollo/server
package. This library doesn't look at or modify the Accept
header, so I assume this is on @apollo/server
. I recommend creating an issue there.
Thanks for replying! I see, I will go ahead and create an issue there!
@chinmayghotkar 👋 Apollo Server maintainer here. AS4 is more particular about accept
headers / content type negotiation. You should be able to bypass our content type negotiation altogether by setting the content-type
header yourself in a plugin like so:
{
async requestDidStart({ response }) {
response.http?.headers.set(
'content-type',
'application/json;v=2',
);
},
},
Let me know if this helps!
@trevor-scheer Hi Trevor, Thanks for the replying! Is the code snippet you sent for response headers or request headers? We are having issues with the request header with the
'accept': 'application/json;v=2'
We are getting a graphql error, so we arent sure if the request header is causing the issue or something else. With the workaround above, we are able to hit the query resolvers.
This is the error we are getting:
{"errors": [{"extensions": {"code": "BAD_REQUEST", "stacktrace": ["BadRequestError: An 'accept' header was provided for this request which does not accept application/json; charset=utf-8 or application/graphql-response+json; charset=utf-8", " at new GraphQLErrorWithCode
@chinmayghotkar Good question. I know it seems counter-intuitive. In Apollo Server, we only inspect your accept
request header if the content-type
header has not been set on the response yet (so that we can determine how to set it).
Here's the relevant code snippet where you can see we bypass the negotiation altogether if the response header is already set.
I see! Thanks for the explanation!
Hi,
We recently made the upgrade to Apollo V4 and started using this integration. When we make requests to our server, we are passing an accept header that looks like this:
'accept': 'application/json;v=2'
but we receive an error message in the response:
"An 'accept' header was provided for this request which does not accept application/json; charset=utf-8 or application/graphql-response+json; charset=utf-8"
we have a workaround in our validation middleware that overrides the the accept header with:
And this workaround seems to allow for us to make graphql requests.
The apollo server initialization:
Was wondering if we are missing some configuration that we need to handle as part of initializing the
startServerAndCreateLambdaHandler()
or when initializing the apollo server? We can use the workaround but we would prefer to implement in the correct way.Edit:
We are also passing
'content-type': 'application/json',
with the headers