Graphql-flutter: Consider QueryResult.rawFetchResult

Created on 3 Aug 2019  Â·  3Comments  Â·  Source: zino-app/graphql-flutter

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

Most helpful comment

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.

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javi11 picture javi11  Â·  3Comments

milind-solutelabs picture milind-solutelabs  Â·  3Comments

rullyalves picture rullyalves  Â·  4Comments

endigo picture endigo  Â·  4Comments

jomag picture jomag  Â·  3Comments