PackageTrack

npm · #4032

@apollo/client

4.2.12apollographql/apollo-client

A fully-featured caching GraphQL client.

Release timeline

723 releases since 2019
2020202120222023202420252026

Releases

  1. 3.5.523 Nov 2021
    Release notes2 sources agree

    Bug Fixes

    • Remove printer: Printer positional parameter from publicly-exported selectHttpOptionsAndBody function, whose addition in #8699 was a breaking change (starting in Apollo Client 3.5.0) for direct consumers of selectHttpOptionsAndBody. <br/> @benjamn in #9103
    Open source →
  2. 3.5.419 Nov 2021
    Release notes

    Apollo Client 3.5.5 (2021-11-23)

    Bug Fixes

    • Remove printer: Printer positional parameter from publicly-exported selectHttpOptionsAndBody function, whose addition in #8699 was a breaking change (starting in Apollo Client 3.5.0) for direct consumers of selectHttpOptionsAndBody. @benjamn in #9103

    Apollo Client 3.5.4 (2021-11-19)

    Notices

    • [Relevant if you use Apollo Client with React Native] Since Apollo Client v3.5.0, CommonJS bundles provided by @apollo/client use a .cjs file extension rather than .cjs.js, so Node.js won't interpret them as ECMAScript modules. While this change should be an implementation detail, it may cause problems for the Metro bundler used by React Native, whose resolver.sourceExts configuration does not include the cjs extension by default.

      As a workaround until this issue is resolved, you can configure Metro to understand the .cjs file extension by creating a metro.config.js file in the root of your React Native project:

      const { getDefaultConfig } = require("metro-config");
      const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues();
      exports.resolver = {
        ...defaultResolver,
        sourceExts: [
          ...defaultResolver.sourceExts,
          "cjs",
        ],
      };
      

    Improvements

    • Restore the ability to pass onError() and onCompleted() to the mutation execution function. @brainkim in #9076

    • Work around webpack 5 errors of the form

      The request 'ts-invariant/process' failed to resolve only because it was resolved as fully specified
      

      by ensuring import ... from 'ts-invariant/process' is internally written to import ... from 'ts-invariant/process/index.js'. @benjamn in #9083

    Apollo Client 3.5.3 (2021-11-17)

    • Avoid rewriting non-relative imported module specifiers in config/rewriteModuleIds.ts script, thereby allowing bundlers to resolve those imports as they see fit. @benjamn in #9073

    • Ensure only current file is matched when running VSCode debugger. @eps1lon in #9050

    Apollo Client 3.5.2 (2021-11-10)

    • Fix useMutation execute function returning non-identical execution functions when passing similar options. @brainkim in #9093

    Apollo Client 3.5.1 (2021-11-09)

    • Remove npm from dependencies, and avoid referencing graphql-js enum value. @brainkim in #9030

    Apollo Client 3.5.0 (2021-11-08)

    Improvements

    • Add updateQuery and updateFragment methods to ApolloCache, simplifying common readQuery/writeQuery cache update patterns. @wassim-k in #8382

    • Field directives and their arguments can now be included along with field argument names when using field policy keyArgs: [...] notation. For example, if you have a Query.feed field that takes an argument called type and uses a @connection(key:...) directive to keep feed data from different queries separate within the cache, you might configure both using the following InMemoryCache field policy:

      new InMemoryCache({
        typePolicies: {
          Query: {
            fields: {
              feed: {
                keyArgs: ["type", "@connection", ["key"]],
              },
            },
          },
        },
      })
      

      @benjamn in #8678

    • Report single MissingFieldError instead of a potentially very large MissingFieldError[] array for incomplete cache reads, improving performance and memory usage. @benjamn in #8734

    • When writing results into InMemoryCache, each written object is now identified using policies.identify after traversing the fields of the object (rather than before), simplifying identification and reducing duplicate work. If you have custom keyFields functions, they still receive the raw result object as their first parameter, but the KeyFieldsContext parameter now provides context.storeObject (the StoreObject just processed by processSelectionSet) and context.readField (a helper function for reading fields from context.storeObject and any References it might contain, similar to readField for read, merge, and cache.modify functions). @benjamn in #8996

    • Ensure cache.identify never throws when primary key fields are missing, and include the source object in the error message when keyFields processing fails. @benjamn in #8679

    • The HttpLink constructor now accepts an optional print function that can be used to customize how GraphQL DocumentNode objects are transformed back into strings before they are sent over the network. @sarahgp in #8699

    • Make @apollo/client/testing a fully-fledged, independent entry point, instead of re-exporting @apollo/client/utilities/testing (which was never an entry point and no longer exists). @benjamn in #8769

    • A new nested entry point called @apollo/client/testing/core has been created. Importing from this entry point instead of @apollo/client/testing excludes any React-related dependencies. @wassim-k in #8687

    • Make cache.batch return the result of calling the options.update function. @benjamn in #8696

    • The NetworkError and ErrorResponse types have been changed to align more closely. @korywka in #8424

    • Include graphql@16 in peer deps. @brainkim in #8997

    • Update zen-observable-ts to eliminate transitive dependency on @types/zen-observable. @benjamn in #8695

    React Refactoring

    Improvements (due to @brainkim in #8875):

    • The useLazyQuery function now returns a promise with the result.
    • The useMutation result now exposes a method which can be reset.

    Bug Fixes (due to @brainkim in #8596):

    • The useQuery and useLazyQuery hooks will now have ObservableQuery methods defined consistently.
    • Calling useLazyQuery methods like startPolling will start the query.
    • Calling the useLazyQuery execution function will now behave more like refetch. previousData will be preserved.
    • standby fetchPolicies will now act like skip: true more consistently.
    • Calling refetch on a skipped query will have no effect (issue #8270).
    • Prevent onError and onCompleted functions from firing continuously, and improving their polling behavior.
    Open source →
    Additional notes2 sources agree

    Notices

    ⚠️ The following advice about metro.config.js should no longer be necessary, as of Apollo Client v3.6.4.

    • [Relevant if you use Apollo Client with React Native] Since Apollo Client v3.5.0, CommonJS bundles provided by @apollo/client use a .cjs file extension rather than .cjs.js, so Node.js won't interpret them as ECMAScript modules. While this change should be an implementation detail, it may cause problems for the Metro bundler used by React Native, whose resolver.sourceExts configuration does not include the cjs extension by default.

      As a workaround until this issue is resolved, you can configure Metro to understand the .cjs file extension by creating a metro.config.js file in the root of your React Native project:

      // NOTE: No longer necessary in @apollo/[email protected]!
      const { getDefaultConfig } = require("metro-config");
      const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues();
      exports.resolver = {
        ...defaultResolver,
        sourceExts: [...defaultResolver.sourceExts, "cjs"],
      };
      

    Improvements

    • Restore the ability to pass onError() and onCompleted() to the mutation execution function. <br/> @brainkim in #9076

    • Work around webpack 5 errors of the form

      The request 'ts-invariant/process' failed to resolve only because it was resolved as fully specified
      

      by ensuring import ... from 'ts-invariant/process' is internally written to import ... from 'ts-invariant/process/index.js'. <br/> @benjamn in #9083

    Open source →
  3. 3.5.317 Nov 2021
    Release notes2 sources agree
    • Avoid rewriting non-relative imported module specifiers in config/rewriteModuleIds.ts script, thereby allowing bundlers to resolve those imports as they see fit. <br/> @benjamn in #9073

    • Ensure only current file is matched when running VSCode debugger. <br/> @eps1lon in #9050

    Open source →
  4. 3.5.210 Nov 2021
    Release notes2 sources agree
    • Fix useMutation execute function returning non-identical execution functions when passing similar options. <br/> @brainkim in #9037
    Open source →
  5. 3.5.19 Nov 2021
    Release notes2 sources agree
    • Remove npm from dependencies, and avoid referencing graphql-js enum value. <br/> @brainkim in #9030
    Open source →
  6. 3.5.08 Nov 2021
    Release notes2 sources agree

    Improvements

    • Add updateQuery and updateFragment methods to ApolloCache, simplifying common readQuery/writeQuery cache update patterns. <br/> @wassim-k in #8382

    • Field directives and their arguments can now be included along with field argument names when using field policy keyArgs: [...] notation. For example, if you have a Query.feed field that takes an argument called type and uses a @connection(key:...) directive to keep feed data from different queries separate within the cache, you might configure both using the following InMemoryCache field policy:

      new InMemoryCache({
        typePolicies: {
          Query: {
            fields: {
              feed: {
                keyArgs: ["type", "@connection", ["key"]],
              },
            },
          },
        },
      });
      

      @benjamn in #8678

    • Report single MissingFieldError instead of a potentially very large MissingFieldError[] array for incomplete cache reads, improving performance and memory usage. <br/> @benjamn in #8734

    • When writing results into InMemoryCache, each written object is now identified using policies.identify after traversing the fields of the object (rather than before), simplifying identification and reducing duplicate work. If you have custom keyFields functions, they still receive the raw result object as their first parameter, but the KeyFieldsContext parameter now provides context.storeObject (the StoreObject just processed by processSelectionSet) and context.readField (a helper function for reading fields from context.storeObject and any References it might contain, similar to readField for read, merge, and cache.modify functions). <br/> @benjamn in #8996

    • Ensure cache.identify never throws when primary key fields are missing, and include the source object in the error message when keyFields processing fails. <br/> @benjamn in #8679

    • The HttpLink constructor now accepts an optional print function that can be used to customize how GraphQL DocumentNode objects are transformed back into strings before they are sent over the network. <br/> @sarahgp in #8699

    • Make @apollo/client/testing a fully-fledged, independent entry point, instead of re-exporting @apollo/client/utilities/testing (which was never an entry point and no longer exists). <br/> @benjamn in #8769

    • A new nested entry point called @apollo/client/testing/core has been created. Importing from this entry point instead of @apollo/client/testing excludes any React-related dependencies. <br/> @wassim-k in #8687

    • Make cache.batch return the result of calling the options.update function. <br/> @benjamn in #8696

    • The NetworkError and ErrorResponse types have been changed to align more closely. <br/> @korywka in #8424

    • Include graphql@16 in peer deps. <br/> @brainkim in #8997

    • Update zen-observable-ts to eliminate transitive dependency on @types/zen-observable. <br/> @benjamn in #8695

    React Refactoring

    Improvements (due to @brainkim in #8875):

    • The useLazyQuery function now returns a promise with the result.
    • The useMutation result now exposes a method which can be reset.

    Bug Fixes (due to @brainkim in #8596):

    • The useQuery and useLazyQuery hooks will now have ObservableQuery methods defined consistently.
    • Calling useLazyQuery methods like startPolling will start the query.
    • Calling the useLazyQuery execution function will now behave more like refetch. previousData will be preserved.
    • standby fetchPolicies will now act like skip: true more consistently.
    • Calling refetch on a skipped query will have no effect (issue #8270).
    • Prevent onError and onCompleted functions from firing continuously, and improving their polling behavior.
    Open source →
  7. 3.5.0-rc.33 Nov 2021pre-release

    Nothing published for this version

  8. 3.5.0-rc.222 Oct 2021pre-release

    Nothing published for this version

  9. 3.5.0-rc.14 Oct 2021pre-release

    Nothing published for this version

  10. 3.5.0-rc.04 Oct 2021pre-release

    Nothing published for this version

  11. 3.5.0-beta.181 Oct 2021pre-release

    Nothing published for this version

  12. 3.5.0-beta.1727 Sept 2021pre-release

    Nothing published for this version

  13. 3.5.0-beta.1620 Sept 2021pre-release

    Nothing published for this version

  14. 3.5.0-beta.1517 Sept 2021pre-release

    Nothing published for this version

  15. 3.5.0-beta.1417 Sept 2021pre-release

    Nothing published for this version

  16. 3.5.0-beta.1313 Sept 2021pre-release

    Nothing published for this version

  17. 3.5.0-beta.1210 Sept 2021pre-release

    Nothing published for this version

  18. 3.5.0-beta.1130 Aug 2021pre-release

    Nothing published for this version

  19. 3.5.0-beta.1030 Aug 2021pre-release

    Nothing published for this version

  20. 3.5.0-beta.926 Aug 2021pre-release

    Nothing published for this version

  21. 3.5.0-beta.824 Aug 2021pre-release

    Nothing published for this version

  22. 3.5.0-beta.723 Aug 2021pre-release

    Nothing published for this version

  23. 3.5.0-beta.618 Aug 2021pre-release

    Nothing published for this version

  24. 3.5.0-beta.59 Aug 2021pre-release

    Nothing published for this version

  25. 3.5.0-beta.44 Aug 2021pre-release

    Nothing published for this version

  26. 3.5.0-beta.33 Aug 2021pre-release

    Nothing published for this version

  27. 3.5.0-beta.22 Aug 2021pre-release

    Nothing published for this version

  28. 3.5.0-beta.129 Jul 2021pre-release

    Nothing published for this version

  29. 3.5.0-beta.028 Jul 2021pre-release

    Nothing published for this version

  30. 3.4.178 Nov 2021
    Release notes2 sources agree

    Improvements

    • Allow TOptions extends FieldFunctionOptions to be passed as final (optional) type parameter of FieldPolicy type. <br/> @VictorGaiva in #9000
    Open source →
  31. 3.4.164 Oct 2021
    Release notes2 sources agree

    Improvements

    • Prevent webpack from misresolving the graphql package as the local @apollo/client/utilities/globals/graphql.js module when module.exports.resolve.preferRelative is enabled in webpack.config.js.

      Note: if you encounter strange module resolution errors like export 'isType' (imported as 'isType') was not found in 'graphql' (possible exports: removeTemporaryGlobals) please try removing preferRelative: true from your webpack.config.js file, or find a way to disable that resolution behavior for packages within node_modules.

      @benjamn in #8862

    • Avoid importing isType from the graphql package internally, to prevent bundlers from including as much as 3.4kB of unnecessary code. <br/> @benjamn in #8891

    • Make client.resetStore and client.clearStore pass appropriate discardWatches option to cache.reset. <br/> @benjamn in #8873

    Open source →
  32. 3.4.1527 Sept 2021
    Release notes2 sources agree

    Bug Fixes

    • Require calling cache.reset({ discardWatches: true }) to make cache.reset discard cache.watches, restoring behavior broken in v3.4.14 by #8826. <br/> @benjamn in #8852
    Open source →
  33. 3.4.1427 Sept 2021
    Release notes2 sources agree

    Bug Fixes

    • Disable InMemoryCache result object canonization by default, to prevent unexpected memory growth and/or reuse of object references, with multiple ways to reenable it (per-cache, per-query, or a mixture of both). <br/> @benjamn in #8822

    • Clear InMemoryCache watches set when cache.reset() called. <br/> @benjamn in #8826

    • Stop excluding observerless queries from refetchQueries: [...] selection. <br/> @benjamn in #8825

    • Prevent optimistic cache evictions from evicting non-optimistic data. <br/> @benjamn in #8829

    • Ensure cache.broadcastWatch passes all relevant WatchOptions to cache.diff as DiffOptions. <br/> @benjamn in #8832

    Open source →
  34. 3.4.1320 Sept 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix componentDidUpate typo in withSubscription higher-order component. <br/> @YarBez in #7506

    • Fix internal canUseSymbol import within @apollo/client/utilities to avoid breaking bundlers/builds. <br/> @benjamn in #8817

    • Tolerate unfreezable objects like Uint8Array and Buffer in maybeDeepFreeze. <br/> @geekuillaume and @benjamn in #8813

    Open source →
  35. 3.4.1217 Sept 2021
    Release notes2 sources agree

    Bug Fixes

    • Improve handling of falsy existing and/or incoming parameters in relayStylePagination field policy helper function. <br/> @bubba and @benjamn in #8733

    • Associate Apollo context with React.createContext (instead of using a local WeakMap) again, so multiple copies of @apollo/client (uncommon) can share the same context. <br/> @benjamn in #8798

    Open source →
  36. 3.4.1110 Sept 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix Vite tree-shaking by calling the checkDEV() function (at least once) in the module that exports it, @apollo/client/utilities/globals/index.ts. <br/> @benjamn in #8767

    Improvements

    • Export PersistedQueryLink namespace from @apollo/client/link/persisted-queries. <br/> @vedrani in #8761

    Documentation

    • Upgrade docs theme for new Algolia-powered search experience. <br/> @trevorblades in #8768
    Open source →
  37. 3.4.1027 Aug 2021
    Release notes2 sources agree

    Improvements

    • Warn when calling refetch({ variables }) instead of refetch(variables), except for queries that declare a variable named $variables (uncommon). <br/> @benjamn in #8702

    Bug Fixes

    • Fix ObservableQuery.getCurrentResult() returning cached data with certain fetch policies. <br/> @brainkim in #8718

    • Prevent ssrMode/ssrForceFetchDelay from causing queries to hang. <br/> @brainkim in #8709

    • Import @apollo/client/utilities/globals internally wherever __DEV__ is used, not just in @apollo/client/**/index.js entry points. <br/> @benjamn in #8720

    Open source →
  38. 3.4.924 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix unhandled Promise rejection warnings/errors whose message is Observable cancelled prematurely. <br/> @benjamn in #8676

    • Enforce that __DEV__ is polyfilled by every @apollo/client/* entry point that uses it. This build step considers not only explicit __DEV__ usage but also __DEV__ references injected near invariant(...) and new InvariantError(...) expressions. <br/> @benjamn in #8689

    Open source →
  39. 3.4.816 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix error thrown by nested keyFields: ["a", ["b", "c"], "d"] type policies when writing results into the cache where any of the key fields (.a, .a.b, .a.c, or .d) have been renamed by query field alias syntax. <br/> @benjamn in #8643

    • Fix regression from PR #8422 (first released in @apollo/[email protected]) that caused result.data to be set to undefined in some cases after ObservableQuery#getCurrentResult reads an incomplete result from the cache. <br/> @benjamn in #8642

    Open source →
  40. 3.4.79 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix accidental reuse of recycled MergeTree objects in StoreWriter class used by InMemoryCache. <br/> @benjamn in #8618
    Open source →
  41. 3.4.69 Aug 2021
    Release notes2 sources agree

    Improvements

    • Reevaluate window.fetch each time HttpLink uses it, if not configured using options.fetch. This change enables a variety of strategies for instrumenting window.fetch, without requiring those strategies to run before @apollo/client/link/http is first imported. <br/> @benjamn in #8603

    • Clarify mutation fetchPolicy options ("network-only" or "no-cache") using MutationFetchPolicy union type. <br/> @benjamn in #8602

    Bug Fixes

    • Restore full @apollo/client/apollo-client.cjs.js CommonJS bundle for older bundlers.

      Note that Node.js and CommonJS bundlers typically use the bundles specified by "main" fields in our generated package.json files, which are all independent and non-overlapping CommonJS modules. However, apollo-client.cjs.js is just one big bundle, so mixing imports of apollo-client.cjs.js with the other CommonJS bundles is discouraged, as it could trigger the dual package hazard. In other words, please don't start using apollo-client.cjs.js if you're not already. <br/>

      @benjamn in #8592

    • Log MissingFieldErrors in ObservableQuery#getCurrentResult using invariant.debug, rather than reporting them via result.error. <br/> @benjamn in #8604

    Open source →
  42. 3.4.54 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix double registration bug for mutation refetchQueries specified using legacy one-time refetchQueries: [{ query, variables }] style. Though the bug is fixed, we recommend using refetchQueries: [query] instead (when possible) to refetch an existing query using its DocumentNode, rather than creating, executing, and then deleting a new query, as the legacy { query, variables } style unfortunately does. <br/> @benjamn in #8586

    • Fix useQuery/useLazyQuery stalling when clients or queries change. <br/> @brainkim in #8589

    Open source →
  43. 3.4.43 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Revert accidental addition of engines.npm section to published version of @apollo/client/package.json. <br/> @benjamn in #8578
    Open source →
  44. 3.4.32 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Fix { ssr: false } causing queries to hang on the client. <br/> @brainkim in #8574
    Open source →
  45. 3.4.22 Aug 2021
    Release notes2 sources agree

    Bug Fixes

    • Use more default type parameters for mutation-related types in react/types/types.ts, to provide smoother backwards compatibility for code using those types explicitly. <br/> @benjamn in #8573
    Open source →
  46. 3.4.129 Jul 2021
    Release notes2 sources agree

    Bug Fixes

    • Initialize stringifyCanon lazily, when canonicalStringify is first called, fixing Uncaught ReferenceError: __DEV__ is not defined errors due to usage of __DEV__ before declaration. <br/> @benjamn in #8557
    Open source →
  47. 3.4.028 Jul 2021
    Release notes

    Apollo Client 3.4.0

    New documentation

    Improvements

    • InMemoryCache now guarantees that any two result objects returned by the cache (from readQuery, readFragment, etc.) will be referentially equal (===) if they are deeply equal. Previously, === equality was often achievable for results for the same query, on a best-effort basis. Now, equivalent result objects will be automatically shared among the result trees of completely different queries. This guarantee is important for taking full advantage of optimistic updates that correctly guess the final data, and for "pure" UI components that can skip re-rendering when their input data are unchanged. @benjamn in #7439

    • Mutations now accept an optional callback function called onQueryUpdated, which will be passed the ObservableQuery and Cache.DiffResult objects for any queries invalidated by cache writes performed by the mutation's final update function. Using onQueryUpdated, you can override the default FetchPolicy of the query, by (for example) calling ObservableQuery methods like refetch to force a network request. This automatic detection of invalidated queries provides an alternative to manually enumerating queries using the refetchQueries mutation option. Also, if you return a Promise from onQueryUpdated, the mutation will automatically await that Promise, rendering the awaitRefetchQueries option unnecessary. @benjamn in #7827

    • Support client.refetchQueries as an imperative way to refetch queries, without having to pass options.refetchQueries to client.mutate. @dannycochran in #7431

    • Improve standalone client.refetchQueries method to support automatic detection of queries needing to be refetched. @benjamn in #8000

    • Fix remaining barriers to loading @apollo/client/core as native ECMAScript modules from a CDN like esm.run. Importing @apollo/client from a CDN will become possible once we move all React-related dependencies into @apollo/client/react in Apollo Client 4. @benjamn in #8266

    • InMemoryCache supports a new method called batch, which is similar to performTransaction but takes named options rather than positional parameters. One of these named options is an onDirty(watch, diff) callback, which can be used to determine which watched queries were invalidated by the batch operation. @benjamn in #7819

    • Allow merge: true field policy to merge Reference objects with non-normalized objects, and vice-versa. @benjamn in #7778

    • Allow identical subscriptions to be deduplicated by default, like queries. @jkossis in #6910

    • Always use POST request when falling back to sending full query with @apollo/client/link/persisted-queries. @rieset in #7456

    • The FetchMoreQueryOptions type now takes two instead of three type parameters (<TVariables, TData>), thanks to using Partial<TVariables> instead of K extends typeof TVariables and Pick<TVariables, K>. @ArnaudBarre in #7476

    • Pass variables and context to a mutation's update function. Note: The type of the update function is now named MutationUpdaterFunction rather than MutationUpdaterFn, since the older type was broken beyond repair. If you are using MutationUpdaterFn in your own code, please use MutationUpdaterFunction instead. @jcreighton in #7902

    • A resultCacheMaxSize option may be passed to the InMemoryCache constructor to limit the number of result objects that will be retained in memory (to speed up repeated reads), and calling cache.reset() now releases all such memory. @SofianHn in #8701

    • Fully remove result cache entries from LRU dependency system when the corresponding entities are removed from InMemoryCache by eviction, or by any other means. @sofianhn and @benjamn in #8147

    • Expose missing field errors in results. @brainkim in #8262

    • Add expected/received variables to No more mocked responses... error messages generated by MockLink. @markneub in #8340

    • The InMemoryCache version of the cache.gc method now supports additional options for removing non-essential (recomputable) result caching data. @benjamn in #8421

    • Suppress noisy Missing cache result fields... warnings by default unless setLogVerbosity("debug") called. @benjamn in #8489

    • Improve interaction between React hooks and React Fast Refresh in development. @andreialecu in #7952

    Potentially disruptive changes

    • To avoid retaining sensitive information from mutation root field arguments, Apollo Client v3.4 automatically clears any ROOT_MUTATION fields from the cache after each mutation finishes. If you need this information to remain in the cache, you can prevent the removal by passing the keepRootFields: true option to client.mutate. ROOT_MUTATION result data are also passed to the mutation update function, so we recommend obtaining the results that way, rather than using keepRootFields: true, if possible. @benjamn in #8280

    • Internally, Apollo Client now controls the execution of development-only code using the __DEV__ global variable, rather than process.env.NODE_ENV. While this change should not cause any visible differences in behavior, it will increase your minified+gzip bundle size by more than 3.5kB, unless you configure your minifier to replace __DEV__ with a true or false constant, the same way you already replace process.env.NODE_ENV with a string literal like "development" or "production". For an example of configuring a Create React App project without ejecting, see this pull request for our React Apollo reproduction template. @benjamn in #8347

    • Internally, Apollo Client now uses namespace syntax (e.g. import * as React from "react") for imports whose types are re-exported (and thus may appear in .d.ts files). This change should remove any need to configure esModuleInterop or allowSyntheticDefaultImports in tsconfig.json, but might require updating bundler configurations that specify named exports of the react and prop-types packages, to include exports like createContext and createElement (example). @devrelm in #7742

    • Respect no-cache fetch policy (by not reading any data from the cache) for loading: true results triggered by notifyOnNetworkStatusChange: true. @jcreighton in #7761

    • The TypeScript return types of the getLastResult and getLastError methods of ObservableQuery now correctly include the possibility of returning undefined. If you happen to be calling either of these methods directly, you may need to adjust how the calling code handles the methods' possibly-undefined results. @benjamn in #8394

    • Log non-fatal invariant.error message when fields are missing from result objects written into InMemoryCache, rather than throwing an exception. While this change relaxes an exception to be merely an error message, which is usually a backwards-compatible change, the error messages are logged in more cases now than the exception was previously thrown, and those new error messages may be worth investigating to discover potential problems in your application. The errors are not displayed for @client-only fields, so adding @client is one way to handle/hide the errors for local-only fields. Another general strategy is to use a more precise query to write specific subsets of data into the cache, rather than reusing a larger query that contains fields not present in the written data. @benjamn in #8416

    • The nextFetchPolicy option for client.watchQuery and useQuery will no longer be removed from the options object after it has been applied, and instead will continue to be applied any time options.fetchPolicy is reset to another value, until/unless the options.nextFetchPolicy property is removed from options. @benjamn in #8465

    • The fetchMore, subscribeToMore, and updateQuery functions returned from the useQuery hook may now return undefined in edge cases where the functions are called when the component is unmounted. @noghartt in #7980

    Bug fixes

    • In Apollo Client 2.x, a refetch operation would always replace existing data in the cache. With the introduction of field policy merge functions in Apollo Client 3, existing field values could be inappropriately combined with incoming field values by a custom merge function that does not realize a refetch has happened.

      To give you more control over this behavior, we have introduced an overwrite?: boolean = false option for cache.writeQuery and cache.writeFragment, and an option called refetchWritePolicy?: "merge" | "overwrite" for client.watchQuery, useQuery, and other functions that accept WatchQueryOptions. You can use these options to make sure any merge functions involved in cache writes for refetch operations get invoked with undefined as their first argument, which simulates the absence of any existing data, while still giving the merge function a chance to determine the internal representation of the incoming data.

      The default behaviors are overwrite: true and refetchWritePolicy: "overwrite", which restores the Apollo Client 2.x behavior, but (if this change causes any problems for your application) you can easily recover the previous merging behavior by setting a default value for refetchWritePolicy in defaultOptions.watchQuery:

      new ApolloClient({
        defaultOptions: {
          watchQuery: {
            refetchWritePolicy: "merge",
          },
        },
      })
      

      @benjamn in #7810

    • Make sure the MockedResponse ResultFunction type is re-exported. @hwillson in #8315

    • Fix polling when used with skip. @brainkim in #8346

    • InMemoryCache now coalesces EntityStore updates to guarantee only one store.merge(id, fields) call per id per cache write. @benjamn in #8372

    • Fix polling when used with <React.StrictMode>. @brainkim in #8414

    • Fix the React integration logging Warning: Can't perform a React state update on an unmounted component. @wuarmin in #7745

    • Make ObservableQuery#getCurrentResult always call queryInfo.getDiff(). @benjamn in #8422

    • Make readField default to reading from current object only when the from option/argument is actually omitted, not when from is passed to readField with an undefined value. A warning will be printed when this situation occurs. @benjamn in #8508

    • The fetchMore, subscribeToMore, and updateQuery functions no longer throw undefined errors. @noghartt in #7980

    Open source →
    Additional notes2 sources agree

    New documentation

    Improvements

    • InMemoryCache now guarantees that any two result objects returned by the cache (from readQuery, readFragment, etc.) will be referentially equal (===) if they are deeply equal. Previously, === equality was often achievable for results for the same query, on a best-effort basis. Now, equivalent result objects will be automatically shared among the result trees of completely different queries. This guarantee is important for taking full advantage of optimistic updates that correctly guess the final data, and for "pure" UI components that can skip re-rendering when their input data are unchanged. <br/> @benjamn in #7439

    • Mutations now accept an optional callback function called onQueryUpdated, which will be passed the ObservableQuery and Cache.DiffResult objects for any queries invalidated by cache writes performed by the mutation's final update function. Using onQueryUpdated, you can override the default FetchPolicy of the query, by (for example) calling ObservableQuery methods like refetch to force a network request. This automatic detection of invalidated queries provides an alternative to manually enumerating queries using the refetchQueries mutation option. Also, if you return a Promise from onQueryUpdated, the mutation will automatically await that Promise, rendering the awaitRefetchQueries option unnecessary. <br/> @benjamn in #7827

    • Support client.refetchQueries as an imperative way to refetch queries, without having to pass options.refetchQueries to client.mutate. <br/> @dannycochran in #7431

    • Improve standalone client.refetchQueries method to support automatic detection of queries needing to be refetched. <br/> @benjamn in #8000

    • Fix remaining barriers to loading @apollo/client/core as native ECMAScript modules from a CDN like esm.run. Importing @apollo/client from a CDN will become possible once we move all React-related dependencies into @apollo/client/react in Apollo Client 4. <br/> @benjamn in #8266

    • InMemoryCache supports a new method called batch, which is similar to performTransaction but takes named options rather than positional parameters. One of these named options is an onDirty(watch, diff) callback, which can be used to determine which watched queries were invalidated by the batch operation. <br/> @benjamn in #7819

    • Allow merge: true field policy to merge Reference objects with non-normalized objects, and vice-versa. <br/> @benjamn in #7778

    • Allow identical subscriptions to be deduplicated by default, like queries. <br/> @jkossis in #6910

    • Always use POST request when falling back to sending full query with @apollo/client/link/persisted-queries. <br/> @rieset in #7456

    • The FetchMoreQueryOptions type now takes two instead of three type parameters (<TVariables, TData>), thanks to using Partial<TVariables> instead of K extends typeof TVariables and Pick<TVariables, K>. <br/> @ArnaudBarre in #7476

    • Pass variables and context to a mutation's update function. Note: The type of the update function is now named MutationUpdaterFunction rather than MutationUpdaterFn, since the older type was broken beyond repair. If you are using MutationUpdaterFn in your own code, please use MutationUpdaterFunction instead. <br/> @jcreighton in #7902

    • A resultCacheMaxSize option may be passed to the InMemoryCache constructor to limit the number of result objects that will be retained in memory (to speed up repeated reads), and calling cache.reset() now releases all such memory. <br/> @SofianHn in #8107

    • Fully remove result cache entries from LRU dependency system when the corresponding entities are removed from InMemoryCache by eviction, or by any other means. <br/> @sofianhn and @benjamn in #8147

    • Expose missing field errors in results. <br/> @brainkim in #8262

    • Add expected/received variables to No more mocked responses... error messages generated by MockLink. <br/> @markneub in #8340

    • The InMemoryCache version of the cache.gc method now supports additional options for removing non-essential (recomputable) result caching data. <br/> @benjamn in #8421

    • Suppress noisy Missing cache result fields... warnings by default unless setLogVerbosity("debug") called. <br/> @benjamn in #8489

    • Improve interaction between React hooks and React Fast Refresh in development. <br/> @andreialecu in #7952

    Potentially disruptive changes

    • To avoid retaining sensitive information from mutation root field arguments, Apollo Client v3.4 automatically clears any ROOT_MUTATION fields from the cache after each mutation finishes. If you need this information to remain in the cache, you can prevent the removal by passing the keepRootFields: true option to client.mutate. ROOT_MUTATION result data are also passed to the mutation update function, so we recommend obtaining the results that way, rather than using keepRootFields: true, if possible. <br/> @benjamn in #8280

    • Internally, Apollo Client now controls the execution of development-only code using the __DEV__ global variable, rather than process.env.NODE_ENV. While this change should not cause any visible differences in behavior, it will increase your minified+gzip bundle size by more than 3.5kB, unless you configure your minifier to replace __DEV__ with a true or false constant, the same way you already replace process.env.NODE_ENV with a string literal like "development" or "production". For an example of configuring a Create React App project without ejecting, see this pull request for our React Apollo reproduction template. <br/> @benjamn in #8347

    • Internally, Apollo Client now uses namespace syntax (e.g. import * as React from "react") for imports whose types are re-exported (and thus may appear in .d.ts files). This change should remove any need to configure esModuleInterop or allowSyntheticDefaultImports in tsconfig.json, but might require updating bundler configurations that specify named exports of the react and prop-types packages, to include exports like createContext and createElement (example). <br/> @devrelm in #7742

    • Respect no-cache fetch policy (by not reading any data from the cache) for loading: true results triggered by notifyOnNetworkStatusChange: true. <br /> @jcreighton in #7761

    • The TypeScript return types of the getLastResult and getLastError methods of ObservableQuery now correctly include the possibility of returning undefined. If you happen to be calling either of these methods directly, you may need to adjust how the calling code handles the methods' possibly-undefined results. <br/> @benjamn in #8394

    • Log non-fatal invariant.error message when fields are missing from result objects written into InMemoryCache, rather than throwing an exception. While this change relaxes an exception to be merely an error message, which is usually a backwards-compatible change, the error messages are logged in more cases now than the exception was previously thrown, and those new error messages may be worth investigating to discover potential problems in your application. The errors are not displayed for @client-only fields, so adding @client is one way to handle/hide the errors for local-only fields. Another general strategy is to use a more precise query to write specific subsets of data into the cache, rather than reusing a larger query that contains fields not present in the written data. <br/> @benjamn in #8416

    • The nextFetchPolicy option for client.watchQuery and useQuery will no longer be removed from the options object after it has been applied, and instead will continue to be applied any time options.fetchPolicy is reset to another value, until/unless the options.nextFetchPolicy property is removed from options. <br/> @benjamn in #8465

    • The fetchMore, subscribeToMore, and updateQuery functions returned from the useQuery hook may now return undefined in edge cases where the functions are called when the component is unmounted <br/> @noghartt in #7980.

    Bug fixes

    • In Apollo Client 2.x, a refetch operation would always replace existing data in the cache. With the introduction of field policy merge functions in Apollo Client 3, existing field values could be inappropriately combined with incoming field values by a custom merge function that does not realize a refetch has happened.

      To give you more control over this behavior, we have introduced an overwrite?: boolean = false option for cache.writeQuery and cache.writeFragment, and an option called refetchWritePolicy?: "merge" | "overwrite" for client.watchQuery, useQuery, and other functions that accept WatchQueryOptions. You can use these options to make sure any merge functions involved in cache writes for refetch operations get invoked with undefined as their first argument, which simulates the absence of any existing data, while still giving the merge function a chance to determine the internal representation of the incoming data.

      The default behaviors are overwrite: true and refetchWritePolicy: "overwrite", which restores the Apollo Client 2.x behavior, but (if this change causes any problems for your application) you can easily recover the previous merging behavior by setting a default value for refetchWritePolicy in defaultOptions.watchQuery:

      new ApolloClient({
        defaultOptions: {
          watchQuery: {
            refetchWritePolicy: "merge",
          },
        },
      });
      

      @benjamn in #7810

    • Make sure the MockedResponse ResultFunction type is re-exported. <br/> @hwillson in #8315

    • Fix polling when used with skip. <br/> @brainkim in #8346

    • InMemoryCache now coalesces EntityStore updates to guarantee only one store.merge(id, fields) call per id per cache write. <br/> @benjamn in #8372

    • Fix polling when used with <React.StrictMode>. <br/> @brainkim in #8414

    • Fix the React integration logging Warning: Can't perform a React state update on an unmounted component. <br/> @wuarmin in #7745

    • Make ObservableQuery#getCurrentResult always call queryInfo.getDiff(). <br/> @benjamn in #8422

    • Make readField default to reading from current object only when the from option/argument is actually omitted, not when from is passed to readField with an undefined value. A warning will be printed when this situation occurs. <br/> @benjamn in #8508

    • The fetchMore, subscribeToMore, and updateQuery functions no longer throw undefined errors <br/> @noghartt in #7980.

    Open source →
  48. 3.4.0-rc.2323 Jul 2021pre-release

    Nothing published for this version

  49. 3.4.0-rc.2222 Jul 2021pre-release

    Nothing published for this version

  50. 3.4.0-rc.2119 Jul 2021pre-release

    Nothing published for this version

  51. 3.4.0-rc.2015 Jul 2021pre-release

    Nothing published for this version

  52. 3.4.0-rc.1912 Jul 2021pre-release

    Nothing published for this version

  53. 3.4.0-rc.189 Jul 2021pre-release

    Nothing published for this version

  54. 3.4.0-rc.176 Jul 2021pre-release

    Nothing published for this version

  55. 3.4.0-rc.166 Jul 2021pre-release

    Nothing published for this version

  56. 3.4.0-rc.1528 Jun 2021pre-release

    Nothing published for this version

  57. 3.4.0-rc.1424 Jun 2021pre-release

    Nothing published for this version

  58. 3.4.0-rc.1323 Jun 2021pre-release

    Nothing published for this version

  59. 3.4.0-rc.1222 Jun 2021pre-release

    Nothing published for this version

  60. 3.4.0-rc.1117 Jun 2021pre-release

    Nothing published for this version