Change8

@apollo/client@4.0.0-rc.7

Breaking Changes
📦 apollo-client
12 breaking5 features🐛 1 fixes1 deprecations🔧 18 symbols

Summary

This release introduces several breaking TypeScript API changes—including read-only operation contexts, removal of certain request fields, and stricter link handler requirements—while adding features like multi-link concatenation and improved type safety.

⚠️ Breaking Changes

  • operation.getContext now returns a Readonly<OperationContext>, breaking code that mutates the context object.
  • ApolloLink.Request passed to ApolloLink.execute no longer accepts operationName and operationType options; these must be removed from request objects.
  • operation.operationType is now a non-null OperationTypeNode, so code that checks for undefined must be updated.
  • operation.operationName is now string | undefined (undefined for anonymous queries) instead of empty string.
  • ApolloLink.concat, ApolloLink.from and ApolloLink.split no longer accept a plain request handler function; handlers must be wrapped in new ApolloLink.
  • transformOperation and validateOperation have been removed from @apollo/client/link/utils; callers must stop importing them and rely on createOperation.
  • Request handlers must now return an Observable; returning null is no longer allowed. Use RxJS EMPTY observable instead.
  • createOperation no longer accepts a context argument as the first parameter; context must be provided in the request object.
  • The TVariables generic argument has been removed from the GraphQLRequest type.
  • The context object returned from operation.getContext() is now frozen, breaking code that mutates it.
  • The forward function is now always provided to request handlers and is no longer optional; custom link signatures must be updated.
  • ApolloLink no longer detects terminating links by function arity, changing warning behavior when forward is called on a terminating link.

Migration Steps

  1. Update code that mutates the object returned by operation.getContext(); treat it as read-only.
  2. Remove operationName and operationType from GraphQLRequest objects passed to ApolloLink.execute.
  3. Adjust checks for operation.operationType to remove undefined handling.
  4. Handle operation.operationName possibly being undefined instead of empty string.
  5. Wrap plain request handler functions with new ApolloLink when using concat, from, or split.
  6. Stop importing transformOperation and validateOperation; rely on createOperation to produce a well-formed Operation.
  7. Change request handlers to return an Observable; replace null returns with RxJS EMPTY.
  8. Pass context inside the request object to createOperation instead of as a separate argument.
  9. Remove the TVariables generic from GraphQLRequest type usages.
  10. Do not attempt to mutate the context object returned from operation.getContext(); it is now frozen.
  11. Update custom link request method signatures to make forward a required parameter.
  12. Be aware that ApolloLink no longer warns about using concat on terminating links; ensure forward is not called on terminating links.

✨ New Features

  • ApolloLink.concat now accepts multiple links to concatenate in a single call.
  • operation.getContext returns a Readonly<OperationContext> improving type safety.
  • operation.operationType is now guaranteed non-null.
  • operation.operationName now correctly reflects anonymous queries with undefined.
  • Many link types have been moved under the ApolloLink namespace for better organization.

🐛 Bug Fixes

  • HTTP multipart handling now throws an error if the connection closes before the final boundary and ignores any data after the final boundary.

🔧 Affected Symbols

operation.getContextApolloLink.RequestApolloLink.executeoperation.operationTypeoperation.operationNameApolloLink.concatApolloLink.fromApolloLink.splittransformOperationvalidateOperationcreateOperationGraphQLRequestApolloLink.OperationObservableEMPTYApolloLink.ForwardFunctionApolloLink.ResultApolloLink namespace types (FetchResult, GraphQLRequest, NextLink)

⚡ Deprecations

  • Types exported from @apollo/client/link are deprecated in favor of namespaced types on ApolloLink (e.g., FetchResult → ApolloLink.Result, GraphQLRequest → ApolloLink.Request, NextLink → ApolloLink.NextLink).