Skip to content

Subscription in Apollo 4: GraphQL errors never trigger error callback with client.subscribe() - intended? #13125

@ItaiYosephi

Description

@ItaiYosephi

Description

After upgrading to Apollo Client 4, GraphQL errors in subscription responses never trigger the error callback. They always arrive in the next callback via result.error, regardless of errorPolicy.

The only difference between error policies:

  • errorPolicy: 'none'data becomes undefined, errors in result.error
  • errorPolicy: 'all'data preserved, errors in result.error

Server response payload

{
  "payload": {
    "data": {
      "mySubscription": { "id": "123", "status": "active" }
    },
    "errors": [
      {
        "message": "Resource not found",
        "path": ["mySubscription", "relatedEntity"],
        "extensions": { "code": "NOT_FOUND" }
      }
    ]
  }
}

Client code

client.subscribe({ query: MySubscription }).subscribe({
  next: (result) => {
    // GraphQL errors always arrive here in result.error
    // With 'none': result.data is undefined
    // With 'all': result.data is preserved
  },
  error: (error) => {
    // Never called (for GraphQL errors at least....)
  },
});

Questions:

  1. Is this the intended behavior for subscriptions in Apollo Client 4?
  2. What errors are expected to trigger the error callback?
  3. Should errorPolicy: 'none' route GraphQL errors to the error callback (as it seemed to in v3)?

Environment

  • @apollo/client: 4.x
  • Multipart HTTP subscriptions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions