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

I want the GraphQLClient instance to return response headers along with data #641

Open
ellvtr opened this issue Jan 8, 2024 · 3 comments

Comments

@ellvtr
Copy link

ellvtr commented Jan 8, 2024

What

I am looking for a way to append the response headers to all responses from my GraphQLClient instance.
Does anyone know how to do that?

I have this setup in a very large application:

const graphQLClientInternal = new GraphQLClient(endpoint, { requestMiddleware, responseMiddleware });
export const graphQLClient = getSdk(graphQLClientInternal);

The 'getSdk' wrapper comes from "@graphql-codegen" which generates TS types from the backend's graphql schema.
We use that exported graphQLClient in hundreds of places allover the application UI.

Why

I need to access the response headers in all the places that consume the GraphQLClient instance. If there is something to be logged or an error in the data, I need to use the "traceparent" header from the client and display it.

How

I thought that responseMiddleware could help with that, the headers are in there as the response: GraphQLClientResponse<T> argument to the responseMiddleware method.

But as the responseMiddleware doesn't get to return anything, I don't get to modify what is passed down the line. Sure, I can modify the 'data' part but that's a hack. Ideally, I'd like the client to return both data and headers.

@ellvtr
Copy link
Author

ellvtr commented Jan 8, 2024

Is there place to discuss with other users?
We could use Gitter - see https://app.gitter.im/#/room/#graphql-request:gitter.im

@jasonkuhrt
Copy link
Owner

Are you saying you want to extend ExecutionResult type with a new httpResponse field?

@ellvtr
Copy link
Author

ellvtr commented May 23, 2024

I later found out, that using rawRequest provides response headers and all other data. Unfortunately, the auto generated "getSdk" has TS errors in that case, plus some other issues. I don't have access to that code anymore, so I don't recall the exact issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants