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

Consider QueryResult.rawFetchResult #371

Closed
micimize opened this issue Aug 3, 2019 · 3 comments
Closed

Consider QueryResult.rawFetchResult #371

micimize opened this issue Aug 3, 2019 · 3 comments

Comments

@micimize
Copy link
Collaborator

micimize commented Aug 3, 2019

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

@gepd
Copy link

gepd commented Sep 12, 2019

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.

@klavs
Copy link
Collaborator

klavs commented Oct 7, 2019

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.

@micimize
Copy link
Collaborator Author

micimize commented Oct 7, 2019

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

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

3 participants