I would like to read an info set in http response header when I make a query to GraphQL server.
When I execute a query with urql client, I only get these infos :
/** Resulting data from an [operation]{@link Operation}. */
export interface OperationResult<Data = any> {
/** The [operation]{@link Operation} which has been executed. */
operation: Operation;
/** The data returned from the Graphql server. */
data?: Data;
/** Any errors resulting from the operation. */
error?: CombinedError;
/** Optional extensions return by the Graphql server. */
extensions?: Record<string, any>;
/** Optional stale flag added by exchanges that return stale results. */
stale?: boolean;
}
Is there a way to get response headers ?
The short answer is, no, urql
in its default behaviour does not expose the response headers of a request as can be seen here: https://github.com/FormidableLabs/urql/blob/master/packages/core/src/internal/fetchSource.ts#L23-L29
It's simply swallowed.
The long answer is, if your replace the fetchExchange
with a custom implementation you can extract whatever information you want. Unfortunately that's obviously custom and some work, but on the other hand, urql
allows for you to drill into its internals and swap this behaviour out.