Skip to content

Releases: apollographql/apollo-client

v4.0.0-alpha.3

20 Mar 17:07
cb2f86c
Compare
Choose a tag to compare
v4.0.0-alpha.3 Pre-release
Pre-release

Major Changes

  • #12457 32e85ea Thanks @jerelmiller! - Network errors triggered by queries now adhere to the errorPolicy. This means that GraphQL errors and network errors now behave the same way. Previously promise-based APIs, such as client.query, would reject the promise with the network error even if errorPolicy was set to ignore. The promise is now resolved with the error property set to the network error instead.

  • #12464 0595f39 Thanks @jerelmiller! - Remove the called property from useQuery.

v3.13.5

20 Mar 16:48
d0cac27
Compare
Choose a tag to compare

Patch Changes

  • #12461 12c8d06 Thanks @jerelmiller! - Fix an issue where a cache-first query would return the result for previous variables when a cache update is issued after simultaneously changing variables and skipping the query.

v4.0.0-alpha.2

19 Mar 17:10
795fd18
Compare
Choose a tag to compare
v4.0.0-alpha.2 Pre-release
Pre-release

Major Changes

  • #12450 876d070 Thanks @jerelmiller! - Remove TSerialized generic argument to ApolloCache. The ApolloCache base cache abstraction now returns unknown for cache.extract which can be overridden by a cache subclass.

  • #12450 876d070 Thanks @jerelmiller! - Remove the TCacheShape generic argument to ApolloClient. client.extract() now returns unknown by default. You will either need to type-cast this to the expected serialized shape, or use the cache.extract() directly from the subclass to get more specific types.

  • #12446 ab920d2 Thanks @jerelmiller! - Removes the defaultOptions option from useQuery. Use options directly or use the global ApolloClient defaultOptions.

  • #12442 c5ead08 Thanks @jerelmiller! - Remove the deprecated canonizeResults option. It was prone to memory leaks. As such, some results that were referentially equal when canonizeResults option was set to true no longer retain the same object identity.

  • #12442 c5ead08 Thanks @jerelmiller! - Remove resetResultIdentities option from InMemoryCache.gc(). This affected object canonization which has been removed.

  • #12451 77e1b13 Thanks @jerelmiller! - Default the TData generic type to unknown in all APIs that use a TData generic argument such as useQuery, client.query, etc.

Patch Changes

  • #12451 77e1b13 Thanks @jerelmiller! - Default TVariables generic type to OperationVariables instead of any throughout the client in areas that did not yet have the default as such.

  • #12454 925548a Thanks @phryneas! - Fix up the 4.0 CommonJS build

v4.0.0-alpha.1

14 Mar 16:36
76c8fd2
Compare
Choose a tag to compare
v4.0.0-alpha.1 Pre-release
Pre-release

Major Changes

  • #12433 b86e50b Thanks @phryneas! - Remove workarounds for streaming with non-WhatWG response bodies to reduce bundle size.

    This removes support for fetch implementations that return Node Streams, Async Iterators or Blob instances as Response.body.

    In the WhatWG Fetch specification, Response.body is specified as a WhatWG ReadableStream.

    At this point in time, this is natively supported in browsers, node and React Native (via react-native-fetch-api, see our setup instructions for React Native).

    If you are using an older fetch polyfill that deviates from the spec, this might not be compatible - for example, node-fetch returns a node Readable instead of a ReadableStream.
    In those cases, please switch to a compatible alternative such as the node-native fetch, or undici.

Minor Changes

  • #12438 5089516 Thanks @phryneas! - Drop rehackt dependency.
    We can now directly import from react without causing build errors in RSC.

  • #12437 4779dc7 Thanks @phryneas! - Remove polyfills for Object.freeze,seal and preventExtensions in React Native

    These polyfills were only necessary until React Native 0.59, which
    patched the problem on
    the React Native side.

    With React Native 0.61, the Map function was completely replaced
    with a native implementation that never had the problems we guarded against.

  • #12438 5089516 Thanks @phryneas! - Add react-server entry point with stubs for normal exports.

v4.0.0-alpha.0

13 Mar 17:44
a0e0d2e
Compare
Choose a tag to compare
v4.0.0-alpha.0 Pre-release
Pre-release

Major Changes

  • #12384 6aa6fd3 Thanks @jerelmiller! - Remove the asyncMap utility function. Instead use one of the RxJS operators that creates Observables from promises, such as from.

  • #12398 8cf5077 Thanks @jerelmiller! - Removes the isApolloError utility function to check if the error object is an ApolloError instance. Use instanceof to check for more specific error types that replace ApolloError.

  • #12379 ef892b4 Thanks @jerelmiller! - Removes the addTypename option from InMemoryCache and MockedProvider. __typename is now always added to the outgoing query document when using InMemoryCache and cannot be disabled.

    If you are using <MockedProvider /> with addTypename={false}, ensure that your mocked responses include a __typename field. This will ensure cache normalization kicks in and behaves more like production.

  • #12396 00f3d0a Thanks @jerelmiller! - Remove the deprecated errors property from useQuery and useLazyQuery. Read errors from the error property instead.

  • #12222 d1a9054 Thanks @jerelmiller! - Drop support for React 16.

  • #12376 a0c996a Thanks @jerelmiller! - Remove deprecated ignoreResults option from useMutation. If you don't want to synchronize component state with the mutation, use useApolloClient to access your client instance and use client.mutate directly.

  • #12384 6aa6fd3 Thanks @jerelmiller! - Unusubscribing from ObservableQuery while a request is in flight will no longer terminate the request by unsubscribing from the link observable.

  • #12367 e6af35e Thanks @jerelmiller! - The previousData property on useLazyQuery will now change only when data changes. Previously previousData would change to the same value as data while the query was loading.

  • #12224 51e6c0f Thanks @jerelmiller! - Remove deprecated partialRefetch option.

  • #12407 8b1390b Thanks @jerelmiller! - Calling refetch with new variables will now set the networkStatus to refetch instead of setVariables.

  • #12384 6aa6fd3 Thanks @jerelmiller! - Remove the iterateObserversSafely utility function.

  • #12398 8cf5077 Thanks @jerelmiller! - Apollo Client no longer wraps errors in ApolloError. ApolloError has been replaced with separate error classes depending on the cause of the error. As such, APIs that return an error property have been updated to use the generic Error type. Use instanceof to check for more specific error types.

    Migration guide

    ApolloError encapsulated 4 main error properties. The type of error would determine which property was set:

    • graphqlErrors - Errors returned from the errors field by the GraphQL server
    • networkError - Any non-GraphQL error that caused the query to fail
    • protocolErrors - Transport-level errors that occur during multipart HTTP subscriptions
    • clientErrors - A space to define custom errors. Mostly unused.

    These errors were mutally exclusive, meaning both networkError and graphqlErrors were never set simultaneously. The following replaces each of these fields from ApolloError.

    graphqlErrors

    GraphQL errors are now encapsulated in a CombinedGraphQLErrors instance. You can access the raw GraphQL errors via the errors property.

    import { CombinedGraphQLErrors } from "@apollo/client";
    
    // ...
    
    const { error } = useQuery(query);
    
    if (error && error instanceof CombinedGraphQLErrors) {
      console.log(error.errors);
    }

    networkError

    Network errors are no longer wrapped and are instead passed through directly.

    const client = new ApolloClient({
      link: new ApolloLink(() => {
        return new Observable((observer) => {
          observer.error(new Error("Test error"));
        });
      }),
    });
    
    // ...
    
    const { error } = useQuery(query);
    
    // error is `new Error('Test error')`;

    protocolErrors

    Protocol errors are now encapsulated in a CombinedProtocolErrors instance. You can access the raw protocol errors via the errors property.

    import { CombinedProtocolErrors } from "@apollo/client";
    
    // ...
    
    const { error } = useSubscription(subscription);
    
    if (error && error instanceof CombinedProtocolErrors) {
      console.log(error.errors);
    }

    clientErrors

    These were unused by the client and have no replacement. Any non-GraphQL or non-protocol errors are now passed through unwrapped.

    Strings as errors

    If the link sends a string error, Apollo Client will wrap this in an Error instance. This ensures error properties are guaranteed to be of type Error.

    const client = new ApolloClient({
      link: new ApolloLink(() => {
        return new Observable((observer) => {
          // Oops we sent a string instead of wrapping it in an `Error`
          observer.error("Test error");
        });
      }),
    });
    
    // ...
    
    const { error } = useQuery(query);
    
    // The error string is wrapped and returned as `new Error('Test error')`;

    Non-error types

    If the link chain sends any other object type as an error, Apollo Client will wrap this in an UnknownError instance with the cause set to the original object. This ensures error properties are guaranteed to be of type Error.

    const client = new ApolloClient({
      link: new ApolloLink(() => {
        return new Observable((observer) => {
          observer.error({ message: "Not a proper error type" });
        });
      }),
    });
    
    // ...
    
    const { error } = useQuery(query);
    
    // error is an `UnknownError` instance. error.cause returns the original object.
  • #12384 6aa6fd3 Thanks @jerelmiller! - Remove fromError utility function. Use throwError instead.

  • #12211 c2736db Thanks @jerelmiller! - Remove the deprecated graphql, withQuery, withMutation, withSubscription, and withApollo hoc components. Use the provided React hooks instead.

  • #12262 10ef733 Thanks @jerelmiller! - Remove itAsync test utility.

  • #12398 8cf5077 Thanks @jerelmiller! - Updates the ServerError and ServerParseError types to be proper Error subclasses. Perviously these were plain Error intances with additional properties added at runtime. All properties are retained, but instanceof checks now work correctly.

    import { ServerError, ServerParseError } from "@apollo/client";
    
    if (error instanceof ServerError) {
      // ...
    }
    
    if (error instanceof ServerParseError) {
      // ....
Read more

v3.13.4

10 Mar 17:06
0d4b09e
Compare
Choose a tag to compare

Patch Changes

  • #12420 fee9368 Thanks @jorenbroekema! - Use import star from rehackt to prevent issues with importing named exports from external CJS modules.

v3.13.3

07 Mar 17:11
cb0ca9a
Compare
Choose a tag to compare

Patch Changes

  • #12362 f6d387c Thanks @jerelmiller! - Fixes an issue where calling observableQuery.getCurrentResult() when the errorPolicy was set to all would return the networkStatus as NetworkStatus.ready when there were errors returned in the result. This has been corrected to report NetworkStatus.error.

    This bug also affected the useQuery and useLazyQuery hooks and may affect you if you check for networkStatus in your component.

v3.13.2

06 Mar 18:17
50f15a3
Compare
Choose a tag to compare

Patch Changes

  • #12409 6aa2f3e Thanks @phryneas! - To mitigate problems when Apollo Client ends up more than once in the bundle, some unique symbols were converted into Symbol.for calls.

  • #12392 644bb26 Thanks @Joja81! - Fixes an issue where the DeepOmit type would turn optional properties into required properties. This should only affect you if you were using the omitDeep or stripTypename utilities exported by Apollo Client.

  • #12404 4332b88 Thanks @jerelmiller! - Show NaN rather than converting to null in debug messages from MockLink for unmatched variables values.

v3.13.1

14 Feb 18:33
356fcc9
Compare
Choose a tag to compare

Patch Changes

v3.13.0

13 Feb 17:11
e93d19f
Compare
Choose a tag to compare

Apollo Client v3.13.0 introduces a new hook, useSuspenseFragment, as a drop-in replacement for useFragment in apps that are using React Suspense. This is the “last” React hook we are introducing in 3.x - we think this rounds out the “big concepts” in our React Suspense and GraphQL fragment story. See the docs for information on this and our other Suspense-supporting hooks. There are some TypeScript quality-of-life improvements shipped in this release for observableQuery.updateQuery and subscribeToMore. Additionally, the return type of updateQuery now includes undefined to allow an early exit from updates. This was always supported at runtime, but was missed on the TypeScript side. On the runtime side, we’ve fixed query deduplication behavior for multipart responses and corrected the error handling in useMutation callbacks. onCompleted and onError in useQuery and useLazyQuery have been deprecated for multiple reasons. See below for full details 👀

Minor Changes

  • #12066 c01da5d Thanks @jerelmiller! - Adds a new useSuspenseFragment hook.

    useSuspenseFragment suspends until data is complete. It is a drop-in replacement for useFragment when you prefer to use Suspense to control the loading state of a fragment. See the documentation for more details.

  • #12174 ba5cc33 Thanks @jerelmiller! - Ensure errors thrown in the onCompleted callback from useMutation don't call onError.

  • #12340 716d02e Thanks @phryneas! - Deprecate the onCompleted and onError callbacks of useQuery and useLazyQuery.
    For more context, please see the related issue on GitHub.

  • #12276 670f112 Thanks @Cellule! - Provide a more type-safe option for the previous data value passed to observableQuery.updateQuery. Using it could result in crashes at runtime as this callback could be called with partial data even though its type reported the value as a complete result.

    The updateQuery callback function is now called with a new type-safe previousData property and a new complete property in the 2nd argument that determines whether previousData is a complete or partial result.

    As a result of this change, it is recommended to use the previousData property passed to the 2nd argument of the callback rather than using the previous data value from the first argument since that value is not type-safe. The first argument is now deprecated and will be removed in a future version of Apollo Client.

    observableQuery.updateQuery(
      (unsafePreviousData, { previousData, complete }) => {
        previousData;
        // ^? TData | DeepPartial<TData> | undefined
    
        if (complete) {
          previousData;
          // ^? TData
        } else {
          previousData;
          // ^? DeepPartial<TData> | undefined
        }
      }
    );
  • #12174 ba5cc33 Thanks @jerelmiller! - Reject the mutation promise if errors are thrown in the onCompleted callback of useMutation.

Patch Changes

  • #12276 670f112 Thanks @Cellule! - Fix the return type of the updateQuery function to allow for undefined. updateQuery had the ability to bail out of the update by returning a falsey value, but the return type enforced a query value.

    observableQuery.updateQuery(
      (unsafePreviousData, { previousData, complete }) => {
        if (!complete) {
          // Bail out of the update by returning early
          return;
        }
    
        // ...
      }
    );
  • #12296 2422df2 Thanks @Cellule! - Deprecate option ignoreResults in useMutation.
    Once this option is removed, existing code still using it might see increase in re-renders.
    If you don't want to synchronize your component state with the mutation, please use useApolloClient to get your ApolloClient instance and call client.mutate directly.

  • #12338 67c16c9 Thanks @phryneas! - In case of a multipart response (e.g. with @defer), query deduplication will
    now keep going until the final chunk has been received.

  • #12276 670f112 Thanks @Cellule! - Fix the type of the variables property passed as the 2nd argument to the subscribeToMore callback. This was previously reported as the variables type for the subscription itself, but is now properly typed as the query variables.