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

'update' is called when 'error' exists and errorPolicy is none #526

Closed
Narretz opened this issue Feb 26, 2019 · 5 comments
Closed

'update' is called when 'error' exists and errorPolicy is none #526

Narretz opened this issue Feb 26, 2019 · 5 comments

Comments

@Narretz
Copy link

Narretz commented Feb 26, 2019

If you have a config like this:

  apollo: {
    something() {
      return {
        query: MyQuery,
        fetchPolicy: 'network-only',

        variables: {
          id: this.id,
        },

        update({ something }) {
          return convert(something);
        },

        error({ graphQLErrors }) {
          console.log('error handler');
        },
      };
    },
  }

and you have graphQLErrors, then update is still called. This is unexpected, and in fact it worked as expected (update is not called) until v3.0.0-beta.10. Then in 878f966, something was changed to hide the GraphQL console error if the error() handler exists.
However, I would expect that vue-apollo respects the errorPolicy of apollo in this case, i.e. by default it's none and a graphQLError means any data is ignored. See https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-config-options-errorPolicy (the docs are for react, but the code is in apollo-client. In fact, since react handles errorPolicy, I think vue-apollo should too.

@ydfzgyj
Copy link
Contributor

ydfzgyj commented Feb 26, 2019

Looks like a good idea since we don't have any code in vue-apollo compatibled with errorPolicy now. Maybe we can also have an errorPolicy prop in ApolloQuery component.

@xeor
Copy link

xeor commented Mar 6, 2019

I think I have the same problem as this issue describes.

I have an ApolloClient like this:

ApolloClient({
  ...
  defaultOptions: {
    query: {
      errorPolicy: 'all'
    }
  }
})

then I have a graphql server that on some fields have special permissions (using graphql directives). So it returns AuthenticationError when some of these fields are in the query. It returns errors in errors, but the data in those fields are null. The other fields are however populated, so I still want the data.

.result(queryresult) is called, but queryresult.data is empty..

@Akryum
Copy link
Member

Akryum commented Oct 20, 2019

vue-apollo now fully supports errorPolicy. I added a test case:

Screenshot from 2019-10-20 16-17-57

@Akryum
Copy link
Member

Akryum commented Oct 20, 2019

Was about time 😅

@sgarcia-dev
Copy link

Given how this is an important part of error handling in apollo client, perhaps an update to the docs of https://apollo.vuejs.org/ would be helpful? Not everyone is moving to the v4 vue apollo docs at the current slowish pace everyone is updating their libraries to support vue 3...
https://www.apollographql.com/docs/react/data/error-handling/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants