Occasionally a user will want a simple way to access protocol-level data, such as headers and cookies (#335) without having to write a custom link. Rather than adding more protocol-level fields to the QueryResult, we should consider adding an "escape hatch" to getting ther raw FetchResult
Hi guys, you can't do something like javascript apollo client do?
const afterwareLink = new ApolloLink((operation, forward) => {
return forward(operation).map(response => {
const context = operation.getContext();
const { response: { headers } } = context;
if (headers) {
const refreshToken = headers.get('x-refresh-token');
if (refreshToken) {
localStorage.setItem('refreshToken', refreshToken);
}
}
return response;
});
});
finally you concatenate all
const httpLinkWithMiddleware = afterwareLink.concat(middlewareLink.concat(httpLink));
It would be easier and consistent.
I think QueryResult should not care about rawFetchResult, because it is a concept of the HttpLink. Imho, HttpLink should add any interesting response data to the context so that any user who does not use HttpLink doesn't have QueryResult.rawFetchResult which means nothing in their case.
Another example would be Rest Link where a single operation may become a set of HTTP requests – there the meaning of rawFetchResult is unclear.
yeah, I think it's best to leave solutions like this to userland. @gepd we do have custom link support, for example
https://github.com/zino-app/graphql-flutter/blob/519381cd1c57515fd26cedb33c68a68d563a6eac/packages/graphql/lib/src/link/auth/link_auth.dart#L9-L38
Most helpful comment
Hi guys, you can't do something like javascript apollo client do?
finally you concatenate all
It would be easier and consistent.