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

For subscriptions, the errorPolicy setting does nothing. #2062

Closed
marfrede opened this issue Aug 14, 2023 · 6 comments
Closed

For subscriptions, the errorPolicy setting does nothing. #2062

marfrede opened this issue Aug 14, 2023 · 6 comments

Comments

@marfrede
Copy link

marfrede commented Aug 14, 2023

Describe the bug

In the case of running an Apollo subscription with a query that results in server-side errors while still returning data, regardless of the errorPolicy setting chosen, the stream always errors out with ApolloError and the expected data cannot be read. This behaviour is expected for errorPolicy: none but neither for errorPolicy: all nor for errorPolicy: ignore.

This makes it impossible to read any data when the response message contains errors. Also this behaviour unexpectedly differs from apollo queries as it only appears for apollo subscriptions and not for apollo queries, which behave as expected.

To Reproduce

Steps to reproduce the behavior:

Run the same Apollo subscription with a query for which the server responds with errors three times, each with a different errorPolicy setting:

apollo.subscribe<SomeSubscriptionPayload>({
  query: AnyQuery,
  variables: { someId },
  errorPolicy: 'all'
}).pipe(tap(console.log), catchError((err) => {console.log(err); return of(undefined)}));

apollo.subscribe<SomeSubscriptionPayload>({
  query: AnyQuery,
  variables: { someId },
  errorPolicy: 'ignore'
}).pipe(tap(console.log), catchError((err) => {console.log(err); return of(undefined)}));

apollo.subscribe<SomeSubscriptionPayload>({
  query: AnyQuery,
  variables: { someId },
  errorPolicy: 'none'
}).pipe(tap(console.log), catchError((err) => {console.log(err); return of(undefined)}));

Now observe that in neither case the response is logged (tap is never reached) but in every case the error can be caught, meaning the stream errors out.

Expected behavior

As expected and as stated in the doc, the response of an Apollo Query differs depending on the errorPolicy setting:

  1. For errorPolicy: none the stream errors out, providing an error message, but no data.
  2. For errorPolicy: ignore the stream nexts, while providing data object but no errors array, and completes
  3. For errorPolicy: all the stream nexts, while providing data and errors array, and completes

Exactly this behaviour is expected for Apollo Subscriptions. Instead, however, the following behaviour is seen here:

  1. For errorPolicy: none the stream errors out, providing an error message, but no data.
  2. For errorPolicy: ignore the stream errors out, providing an error message, but no data.
  3. For errorPolicy: all the stream errors out, providing an error message, but no data.

Any change of the errorPolicy does nothing to the response.

Environment

- @angular/cli@16.1.7
- @angular/core@16.1.8
- @apollo/client@3.7.17
- apollo-angular@5.0.0
- graphql@16.6.0
- typescript@5.1.6
@PowerKiKi
Copy link
Collaborator

Can you create a reproduction case that proves that @apollo/client works as expected, but apollo-angular fails ?

@marfrede
Copy link
Author

@PowerKiKi I will look into this.

@marfrede
Copy link
Author

@PowerKiKi I was actually able to reproduce the opposite. The same error also exists when using @apollo/client with react.

@PowerKiKi
Copy link
Collaborator

Thanks for investigating that. It's as I expected. I'll close this issue and we can follow the development on the pre-existing one.

@PowerKiKi PowerKiKi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2023
@marfrede
Copy link
Author

For anyone with the same problem the new issue can be tracked here: apollographql/apollo-client#10559
It should be merged any moment now 😊🎉

@jerelmiller
Copy link

Hey all 👋

Apollo Client maintainer here. Just wanted to let you know that this issue is fixed and has been released in @apollo/client v3.8.2. Thanks!

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