Apollo-client: errorPolicy not working

Created on 8 Dec 2017  路  19Comments  路  Source: apollographql/apollo-client

When setting errorPolicy to all. Neither errors nor data.X is in the response. Setting it to ignore, i get the partial data but no error, using the default configuration i get data.error but not query data.

Intended outcome:
errorPolicy should behave as documented: Add a errors field next to data in case of an error

Actual outcome:
There is neither errors nor response data

How to reproduce the issue:
Create a graphql object like this:

const withDataAndErrors = graphql(QUERY_THAT_HAS_DATA_AND_ERRORS, {
  options: {
    errorPolicy: 'all'
  }
});

that query should return something like:

{
  "data": {...},
  "errors": [...]
}

Version

Most helpful comment

This is fixed on master and will be released this week 馃尞

sorry about the delay here!

All 19 comments

Adjusting the test related to errorPolicy all to this:

it('returns errors with data if errorPolicy is all', () => {
      const queryManager = mockQueryManager({
        request: { query, variables },
        result: { data: dataOne, errors: [error] },
      });

      const observable = queryManager.watchQuery({
        query,
        variables,
        errorPolicy: 'all',
      });

      return observable.result().then(result => {
        expect(result.data).toEqual(dataOne);
        expect(result.errors).toEqual([error]);
        const currentResult = observable.currentResult();
        expect(currentResult.loading).toBe(false);
        expect(currentResult.errors).toEqual([error]);
        expect(currentResult.error).toBeUndefined();
      });
    });

(so simply adding data)

you'll see that the data is not passed to the result... that the error is missing in the react component seems like a apollo-react related bug.

I'm getting this, too. I set up a repo (with a more specific use case, albeit) to replicate it. I'll drop this in the related react-apollo ticket as well.

I'm getting something else. In case of GraphQL errors, the errors are ignored but the client but the error data in the response exist. I have to handle them myself. I cannot infer from the documentation whether this is the intended behavior.

In case of 'ignore' policy, there are neither errors thrown nor error data in the response.

I'm using apollo angular.

@Axure Same, actually. If I inspect the response in Chrome's network tab, I see errors. But it seems inaccessible to the component.

I've digged deeper in the code and I think the reason for the missing data might be here:
https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/QueryManager.ts#L1044

It only writes the query result into the datastore if the errorPolicy is set to "ignore"... something like

errorPolicy === 'ignore' || errorPolicy === 'all'

would do the trick

I'm running into the same issue with the all option while using angular1-apollo with apollo-client 2.0. result.errors is returned, but result.data is null. When checking the POST /graphql, result.data is being sent over the wire, it just gets dropped by apollo-client it appears.

@Matt-Dionis could you test my proposed solution and give some feedback if it is working as it should? Then I'll make a pull request.

I'll give it a shot later today.

@Matt-Dionis have you tried the proposed solution?
any progress on this issue?

@Torsten85, @amok I tried out the proposed solution and it worked for me. I now see both result.data and result.errors when I set errorPolicy to all.

@Matt-Dionis thanks for the answer
I'm testing it too, but in my case it's not the only step to get everything working
the suggested approach resolves current issue but not apollographql/react-apollo/issues/1389
it seems like react-apollo hoc doesn't set errors prop for wrapped component
trying to write some monkeypatch as a workaround before everything will get fixed in a proper manner

I see. I'm using angular1-apollo to be more specific.

dirty patch is posted here apollographql/react-apollo/issues/1389

This is fixed on master and will be released this week 馃尞

sorry about the delay here!

Since this is now fixed, someone "offical" should comment on this one https://github.com/apollographql/react-apollo/pull/1630. Thanks!

@jbaxleyiii , can you take a peek at https://github.com/apollographql/react-apollo/pull/1630 ? It seems related to this issue.

Any update on the PR? Correct me if I am wrong but It looks like the fix is still not yet merged.

https://github.com/apollographql/apollo-client/pull/2956/commits

@arvinsim Looks like it is merged now (apollo-client 2.2.5). I upgraded to 2.2.5 yesterday and changed errorPolicy to all and things are now working as expected. 馃憤

Was this page helpful?
0 / 5 - 0 ratings