Releases: apollographql/apollo-client
v3.6.5
Bug Fixes (from CHANGELOG.md
)
-
Restore pre-v3.6
variables
replacement behavior ofObservableQuery#reobserve
method, fixing a regression that prevented removal of variables.
@benjamn in #9741 -
Preserve
previousData
even when different query or client provided touseQuery
, instead of resettingpreviousData
to undefined in those cases, matching behavior prior to v3.6.0.
@benjamn in #9734 -
Fix bug where
onCompleted()
andonError()
are stale foruseMutation()
.
@charle692 in #9740 -
Limit scope of
DeepMerger
object reuse, and avoid usingObject.isFrozen
, which can introduce differences between development and production if objects that were frozen usingObject.freeze
in development are left unfrozen in production.
@benjamn in #9742 -
Properly merge
variables
from originaluseLazyQuery(query, { variables })
withvariables
passed to execution function.
@benjamn in #9758
What's Changed (auto-generated by GitHub)
- Preserve
previousData
even when different client or query passed touseQuery
by @benjamn in #9734 - Restore pre-v3.6
variables
replacement behavior ofObservableQuery#reobserve
method by @benjamn in #9741 - Clarify modifying response data in link docs by @hatched-kade in #9430
- adds documentation on file uploads by @jpvajda in #9744
- Fix improper syntax with spread operator by @mongodben in #9441
- Reduce confusion about the query component by @jpvajda in #9747
- Fix bug where onCompleted and onError are stale for useMutation. onCompleted and onError could not be changed while a mutation is executing. by @charle692 in #9740
- Restrict
DeepMerger
mutable object reuse to fix subtle production-only bug by @benjamn in #9742 - Merge
variables
from originaluseLazyQuery(query, { variables })
withvariables
passed to execution function by @benjamn in #9758
New Contributors
- @hatched-kade made their first contribution in #9430
- @mongodben made their first contribution in #9441
- @charle692 made their first contribution in #9740
Full Changelog: v3.6.4...v3.6.5
v3.6.4
Bug Fixes (from CHANGELOG.md
)
-
Guarantee
Concast
cleanup withoutObservable cancelled prematurely
rejection, potentially solving long-standing issues involving that error.
@benjamn in #9701 -
Ensure
useSubscription
subscriptions are properly restarted after unmounting/remounting by React 18 in<StrictMode>
.
@kazekyo in #9707
Improvements (from CHANGELOG.md
)
-
Internalize
useSyncExternalStore
shim, for more control thanuse-sync-external-store
provides, fixing some React Native issues.
@benjamn in #9675 and #9709 -
Provide
@apollo/client/**/*.cjs.native.js
versions of every@apollo/client/**/*.cjs
bundle (including dependenciests-invariant
andzen-observable-ts
) to help React Native's Metro bundler automatically resolve CommonJS entry point modules. These changes should render unnecessary the advice we gave in the v3.5.4 section below aboutmetro.config.js
.
@benjamn in #9716 -
Handle falsy
incoming
data more gracefully inoffetLimitPagination().merge
function.
@shobhitsharma in #9705
What's Changed (auto-generated by GitHub)
- Poll interval docs update by @jpvajda in #9687
- [docs] Fix markdown bug in rest link by @ryanrhee in #9698
- Internalize
useSyncExternalStore
shim, for more control thanuse-sync-external-store
provides by @benjamn in #9675 - Guarantee
Concast
cleanup withoutObservable cancelled prematurely
rejection by @benjamn in #9701 - docs: fix code snippet by @santiph in #9703
- Update example headers with authentication by @theill in #9621
- Fix a misplaced semicolon by @mlocher in #9498
- Correct GraphQL variable name "text" to "type" by @FumioNonaka-ksj in #9529
- Add apollo-multi-endpoint-link to community links by @jean9696 in #9301
readQuery
clarification by @avinoamsn in #9195- Update authentication.mdx by @volokolamskspb in #8630
- Add apollo-link-observable to community links by @dragozin in #8234
- apollo-codegen is deprecated, but the tooling documentation still suggests it by @krainboltgreene in #7517
- chore: corrected body params by @jpvajda in #9711
useSyncExternalStore
refinements by @benjamn in #9709- Help React Native import
@apollo/client/main.cjs
and other CommonJS bundles by @benjamn in #9716 - Revamping the "Why Apollo Client" article by @rkoron007 in #9719
- Fix useSubscription bug in React v18 StrictMode (#9664) by @kazekyo in #9707
New Contributors
- @ryanrhee made their first contribution in #9698
- @santiph made their first contribution in #9703
- @theill made their first contribution in #9621
- @mlocher made their first contribution in #9498
- @FumioNonaka-ksj made their first contribution in #9529
- @jean9696 made their first contribution in #9301
- @avinoamsn made their first contribution in #9195
- @volokolamskspb made their first contribution in #8630
- @dragozin made their first contribution in #8234
- @krainboltgreene made their first contribution in #7517
- @kazekyo made their first contribution in #9707
Full Changelog: v3.6.3...v3.6.4
v3.6.3
Bug Fixes (from CHANGELOG.md
)
-
Simplify
useQuery(query, { defaultOptions })
default options processing in order to fix bug whereskip: true
queries failed to execute upon switching toskip: false
.
@benjamn in #9665 -
Add tests of skipping/unskipping and
useLazyQuery
withdefaultOptions
, and fix a bug causing duplicate requests.
@benjamn in #9666 -
Update
ts-invariant
to version 0.10.2 to fix source map warnings.
@benjamn in #9672 -
Test that
useQuery
queries withskip: true
do not stall server-side rendering.
@nathanmarks and @benjamn in #9677 -
Prevent
useLazyQuery
from making duplicate requests when its execution function is first called, and stop rejecting thePromise
it returns whenresult.error
is defined.
@benjamn in #9684 -
Fix issue with
useQuery
returningloading: true
state during server-side rendering withskip: true
.
@nathanmarks in #9679
What's Changed (auto-generated by GitHub)
- Drastically simplify
useQuery
default options processing by @benjamn in #9665 - Docs: fix typo in subscriptions.mdx by @pobch in #9663
- Update
ts-invariant
to version 0.10.2 to fix source map warnings by @benjamn in #9672 - Update queries.mdx by @anilpai in #5466
- Fix failing regression test for skipped SSR
useQuery
stuck in standby by @benjamn in #9677 - Add a comment about a new use of the content-type header by @glasser in #9683
- Add missing assumeImmutableResults documentation by @henryqdineen in #9680
- Prevent
useLazyQuery
from making duplicate requests when execution function first called by @benjamn in #9684 - Fix issue with
useQuery
returningloading: true
state during server-side rendering withskip: true
by @nathanmarks in #9679 - Add description & example of how to handle multiple parameters in read() when declaring typePolicies. by @Moristotle in #6755
- Add link to ts-transform-graphql-tag in the performance docs by @hcharley in #5608
New Contributors
- @anilpai made their first contribution in #5466
- @nathanmarks made their first contribution in #9679
- @Moristotle made their first contribution in #6755
- @hcharley made their first contribution in #5608
Full Changelog: v3.6.2...v3.6.3
3.6.2
What's Changed
- fix Missing getServerSnapshot on React 18 and Next 12 by @hungphongbk in #9652
- Fix persistedQueries to pull graphqlErrors from networkErrors by @redaid113 in #9410
- Update Apollo PersistedQueries in the Apollo BatchHTTP Link by @iamchathu in #9637
- Fix code snippets for SubscriptionClient by @rkoron007 in #9634
- Correct the wrong link in ROADMAP.md by @yukukotani in #9650
- Update Copyright year in LICENSE by @garritfra in #9630
New Contributors
- @iamchathu made their first contribution in #9637
- @hungphongbk made their first contribution in #9652
- @yukukotani made their first contribution in #9650
- @redaid113 made their first contribution in #9410
Full Changelog: v3.6.1...v3.6.2
v3.6.1
What's Changed
- Remove
WatchQueryOptions["fetchBlockingPromise"]
option due to regressions by @benjamn in #9636 - chore(deps): update dependency graphql-ws to v5.8.1 by @renovate in #9592
- Update Full-stack tutorial links to point to Odyssey by @rkoron007 in #9610
- changes the way the parser filters the array of definitions by @rasulomaroff in #9622
- chore: updates roadmap by @jpvajda in #9628
New Contributors
- @rasulomaroff made their first contribution in #9622
- @jpvajda made their first contribution in #9628
Full Changelog: v3.6.0...v3.6.1
3.6.0
Note: for the most up-to-date version of this information, see
CHANGELOG.md
Apollo Client 3.6.0 (2022-04-26)
Potentially disruptive changes
-
Calling
fetchMore
for queries using thecache-and-network
ornetwork-only
fetch policies will no longer trigger additional network requests when cache results are complete. Instead, those complete cache results will be delivered as if using thecache-first
fetch policy.
@benjamn in #9504 -
Reimplement
useQuery
anduseLazyQuery
to use the proposeduseSyncExternalStore
API from React 18.
@brainkim and @benjamn in #8785 and #9596 -
Fixed bug where the
useLazyQuery
execution function would always use therefetch
method ofObservableQuery
, instead of properly reapplying the currentfetchPolicy
using thereobserve
method.
@benjamn in #9564Since this
reobserve
method is useful and used internally, we have now exposed it asuse[Lazy]Query(...).reobserve
(which optionally takes aPartial<WatchQueryOptions>
of new options), to supplement the existingrefetch
method. Note thatreobserve
permanently updates thevariables
and other options of theObservableQuery
, unlikerefetch({ ...variables })
, which does not save thosevariables
. -
The internal use of
options.fetchBlockingPromise
byuseQuery
anduseLazyQuery
may slightly delay the delivery of network results, compared to previous versions of Apollo Client. Since network results are already delivered asynchronously, these timing differences should not be disruptive in most cases. Nevertheless, please open an issue if the timing differences cause problems for your applications.
@benjamn in #9599
React 18
In both its peerDependencies
and its internal implementation, Apollo Client v3.6 should no longer prevent you from updating to React 18 in your applications.
Internally, we have refactored useQuery
and useLazyQuery
to be implemented in terms of React's new (shimmable) useSyncExternalStore
hook, demonstrating Apollo Client can serve as an external store with a referentially stable, synchronous API, as needed by React.
As part of this refactoring, we also improved the behavior of useQuery
and useLazyQuery
when used in <React.StrictMode>
, which double-renders components in development. While this double-rendering always results in calling useQuery
twice, forcing Apollo Client to create and then discard an unnecessary ObservableQuery
object, we now have multiple defenses in place against executing any network queries for the unused ObservableQuery
objects.
In upcoming v3.6.x and v3.7 (beta) releases, we will be completely overhauling our server-side rendering utilities (getDataFromTree
et al.), and introducing suspenseful versions of our hooks, to take full advantage of the new patterns React 18+ enables for data management libraries like Apollo Client.
Improvements
-
Allow
BatchLink
to cancel queued and in-flight operations.
@PowerKiKi and @benjamn in #9248 -
Add
GraphQLWsLink
in@apollo/client/link/subscriptions
. This link is similar to the existingWebSocketLink
in@apollo/client/link/ws
, but uses the newergraphql-ws
package and protocol instead of the oldersubscriptions-transport-ws
implementation. This functionality was technically first released in@apollo/client@3.5.10
, but semantically belongs in the 3.6.0 minor version.
@glasser in #9369 -
Allow passing
defaultOptions
touseQuery
to avoid clobbering/resetting existing options whenuseQuery
is called repeatedly.
@benjamn in #9563, superseding #9223 -
Provide additional context to
nextFetchPolicy
functions to assist withfetchPolicy
transitions. More details can be found in thenextFetchPolicy
documentation.
@benjamn in #9222 -
Remove nagging deprecation warning about passing an
options.updateQuery
function tofetchMore
.
@benjamn in #9504 -
Let
addTypenameToDocument
take anyASTNode
(includingDocumentNode
, as before).
@benjamn in #9595 -
Set
useMutation
internalisMounted
variable totrue
again when component remounted.
@devpeerapong in #9561
New Contributors
- @levrik made their first contribution in #9299
- @julienfouilhe made their first contribution in #9339
- @ctataryn made their first contribution in #9434
- @hennessyevan made their first contribution in #9470
- @rkoron007 made their first contribution in #9500
- @jergason made their first contribution in #9419
- @devpeerapong made their first contribution in #9561
3.5.x
Apollo Client 3.5.5 (2021-11-23)
Bug Fixes
- Remove
printer: Printer
positional parameter from publicly-exportedselectHttpOptionsAndBody
function, whose addition in #8699 was a breaking change (starting in Apollo Client 3.5.0) for direct consumers ofselectHttpOptionsAndBody
.
@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, whoseresolver.sourceExts
configuration does not include thecjs
extension by default.As a workaround until this issue is resolved, you can configure Metro to understand the
.cjs
file extension by creating ametro.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()
andonCompleted()
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 toimport ... 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)
Apollo Client 3.5.0 (2021-11-08)
Improvements
-
Add
updateQuery
andupdateFragment
methods toApolloCache
, simplifying commonreadQuery
/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 aQuery.feed
field that takes an argument calledtype
and uses a@connection(key:...)
directive to keepfeed
data from different queries separate within the cache, you might configure both using the followingInMemoryCache
field policy:new InMemoryCache({ typePolicies: { Query: { fields: { feed: { keyArgs: ["type", "@connection", ["key"]], }, }, }, }, })
-
Report single
MissingFieldError
instead of a potentially very largeMissingFieldError[]
array for incomplete cache reads, improving performance and memory usage.
@benjamn in #8734 -
When writing results into
InMemoryCache
, each written object is now identified usingpolicies.identify
after traversing the fields of the object (rather than before), simplifying identification and reducing duplicate work. If you have customkeyFields
functions, they still receive the raw result object as their first parameter, but theKeyFieldsContext
parameter now providescontext.storeObject
(theStoreObject
just processed byprocessSelectionSet
) andcontext.readField
(a helper function for reading fields fromcontext.storeObject
and anyReference
s it might contain, similar toreadField
forread
,merge
, andcache.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 whenkeyFields
processing fails.
@benjamn in #8679 -
The
HttpLink
constructor now accepts an optionalprint
function that can be used to customize how GraphQLDocumentNode
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 theoptions.update
function.
@benjamn in #8696 -
The
NetworkError
andErrorResponse
types have been changed to align more closely.
@korywka in #8424 -
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
anduseLazyQuery
hooks will now haveObservableQuery
methods defined consistently. - Calling
useLazyQuery
methods likestartPolling
will start the query. - Calling the
useLazyQuery
execution function will now behave more likerefetch
.previousData
will be preserved. standby
fetchPolicies will now act likeskip: true
more consistently.- Calling
refetch
on a skipped query will have no effect (issue #8270). - Prevent
onError
andonCompleted
functions from firing continuously, and improving their polling behavior.
3.4.0
Apollo Client 3.4.0
New documentation
- Refetching queries with
client.refetchQueries
.
@StephenBarlow and @benjamn in #8265
Improvements
-
InMemoryCache
now guarantees that any two result objects returned by the cache (fromreadQuery
,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 theObservableQuery
andCache.DiffResult
objects for any queries invalidated by cache writes performed by the mutation's finalupdate
function. UsingonQueryUpdated
, you can override the defaultFetchPolicy
of the query, by (for example) callingObservableQuery
methods likerefetch
to force a network request. This automatic detection of invalidated queries provides an alternative to manually enumerating queries using therefetchQueries
mutation option. Also, if you return aPromise
fromonQueryUpdated
, the mutation will automatically await thatPromise
, rendering theawaitRefetchQueries
option unnecessary.
@benjamn in #7827 -
Support
client.refetchQueries
as an imperative way to refetch queries, without having to passoptions.refetchQueries
toclient.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 calledbatch
, which is similar toperformTransaction
but takes named options rather than positional parameters. One of these named options is anonDirty(watch, diff)
callback, which can be used to determine which watched queries were invalidated by thebatch
operation.
@benjamn in #7819 -
Allow
merge: true
field policy to mergeReference
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 usingPartial<TVariables>
instead ofK extends typeof TVariables
andPick<TVariables, K>
.
@ArnaudBarre in #7476 -
Pass
variables
andcontext
to a mutation'supdate
function. Note: The type of theupdate
function is now namedMutationUpdaterFunction
rather thanMutationUpdaterFn
, since the older type was broken beyond repair. If you are usingMutationUpdaterFn
in your own code, please useMutationUpdaterFunction
instead.
@jcreighton in #7902 -
A
resultCacheMaxSize
option may be passed to theInMemoryCache
constructor to limit the number of result objects that will be retained in memory (to speed up repeated reads), and callingcache.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 -
Add expected/received
variables
toNo more mocked responses...
error messages generated byMockLink
.
@markneub in #8340 -
The
InMemoryCache
version of thecache.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 unlesssetLogVerbosity("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 thekeepRootFields: true
option toclient.mutate
.ROOT_MUTATION
result data are also passed to the mutationupdate
function, so we recommend obtaining the results that way, rather than usingkeepRootFields: true
, if possible.
@benjamn in #8280 -
Internally, Apollo Client now controls the execution of development-only code using the
__DEV__
global variable, rather thanprocess.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 atrue
orfalse
constant, the same way you already replaceprocess.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 configureesModuleInterop
orallowSyntheticDefaultImports
intsconfig.json
, but might require updating bundler configurations that specify named exports of thereact
andprop-types
packages, to include exports likecreateContext
andcreateElement
(example).
@devrelm in #7742 -
Respect
no-cache
fetch policy (by not reading anydata
from the cache) forloading: true
results triggered bynotifyOnNetworkStatusChange: true
.
@jcreighton in #7761 -
The TypeScript return types of the
getLastResult
andgetLastError
methods ofObservableQuery
now correctly include the possibility of returningundefined
. 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 intoInMemoryCache
, 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 ...
3.3.0
Apollo Client 3.3.0
Bug Fixes
-
Update
@wry/equality
to consider undefined properties equivalent to missing properties.
@benjamn in #7108 -
Prevent memory leaks involving unused
onBroadcast
function closure created inApolloClient
constructor.
@kamilkisiela in #7161 -
Provide default empty cache object for root IDs like
ROOT_QUERY
, to avoid differences in behavior before/afterROOT_QUERY
data has been written intoInMemoryCache
.
@benjamn in #7100 -
Cancel
queryInfo.notifyTimeout
inQueryInfo#markResult
to prevent unnecessary network requests when using aFetchPolicy
ofcache-and-network
ornetwork-only
in a React component with multipleuseQuery
calls.
@benjamn in #7347
Potentially breaking changes
-
Ensure
cache.readQuery
andcache.readFragment
always returnTData | null
, instead of throwingMissingFieldError
exceptions when missing fields are encountered.
@benjamn in #7098Since this change converts prior exceptions to
null
returns, and sincenull
was already a possible return value according to theTData | null
return type, we are confident this change will be backwards compatible (as long asnull
was properly handled before). -
HttpLink
will now automatically strip any unusedvariables
before sending queries to the GraphQL server, since those queries are very likely to fail validation, according to the All Variables Used rule in the GraphQL specification. If you depend on the preservation of unused variables, you can restore the previous behavior by passingincludeUnusedVariables: true
to theHttpLink
constructor (which is typically passed asoptions.link
to theApolloClient
constructor).
@benjamn in #7127 -
Ensure
MockLink
(used byMockedProvider
) returns mock configuration errors (e.g.No more mocked responses for the query ...
) through the Link'sObservable
, instead of throwing them. These errors are now available through theerror
property of a result.
@hwillson in #7110Returning mock configuration errors through the Link's
Observable
was the default behavior in Apollo Client 2.x. We changed it for 3, but the change has been problematic for those looking to migrate from 2.x to 3. We've decided to change this back with the understanding that not many people want or are relying onMockLink
's throwing exception approach. If you want to change this functionality, you can define custom error handling throughMockLink.setOnError
. -
Unsubscribing the last observer from an
ObservableQuery
will once again unsubscribe from the underlying networkObservable
in all cases, as in Apollo Client 2.x, allowing network requests to be cancelled by unsubscribing.
@javier-garcia-meteologica in #7165 and #7170. -
The independent
QueryBaseOptions
andModifiableWatchQueryOptions
interface supertypes have been eliminated, and their fields are now defined byQueryOptions
.
@DCtheTall in #7136 -
Internally, Apollo Client now avoids nested imports from the
graphql
package, importing everything from the top-level package instead. For example,import { visit } from "graphql/language/visitor"
is now just
import { visit } from "graphql"
Since the
graphql
package uses.mjs
modules, your bundler may need to be configured to recognize.mjs
files as ECMAScript modules rather than CommonJS modules.
@benjamn in #7185
Improvements
-
Support inheritance of type and field policies, according to
possibleTypes
.
@benjamn in #7065 -
Allow configuring custom
merge
functions, including themerge: true
andmerge: false
shorthands, in type policies as well as field policies.
@benjamn in #7070 -
The verbosity of Apollo Client console messages can be globally adjusted using the
setLogVerbosity
function:import { setLogVerbosity } from "@apollo/client"; setLogVerbosity("log"); // display all messages setLogVerbosity("warn"); // display only warnings and errors (default) setLogVerbosity("error"); // display only errors setLogVerbosity("silent"); // hide all console messages
Remember that all logs, warnings, and errors are hidden in production.
@benjamn in #7226 -
Modifying
InMemoryCache
fields that havekeyArgs
configured will now invalidate only the field value with matching key arguments, rather than invalidating all field values that share the same field name. IfkeyArgs
has not been configured, the cache must err on the side of invalidating by field name, as before.
@benjamn in #7351 -
Shallow-merge
options.variables
when combining existing or default options with newly-provided options, so new variables do not completely overwrite existing variables.
@amannn in #6927 -
Avoid displaying
Cache data may be lost...
warnings for scalar field values that happen to be objects, such as JSON data.
@benjamn in #7075 -
In addition to the
result.data
property,useQuery
anduseLazyQuery
will now provide aresult.previousData
property, which can be useful when a network request is pending andresult.data
is undefined, sinceresult.previousData
can be rendered instead of rendering an empty/loading state.
@hwillson in #7082 -
Passing
validate: true
to theSchemaLink
constructor will enable validation of incoming queries against the local schema before execution, returning validation errors inresult.errors
, just like a non-local GraphQL endpoint typically would.
@amannn in #7094 -
Allow optional arguments in
keyArgs: [...]
arrays forInMemoryCache
field policies.
@benjamn in #7109 -
Avoid registering
QueryPromise
whenskip
istrue
during server-side rendering.
@izumin5210 in #7310 -
ApolloCache
objects (includingInMemoryCache
) may now be associated with or disassociated from individual reactive variables by callingreactiveVar.attachCache(cache)
and/orreactiveVar.forgetCache(cache)
.
@benjamn in #7350
3.2.0
Apollo Client 3.2.0
Bug Fixes
-
Use
options.nextFetchPolicy
internally to restore originalFetchPolicy
after polling withfetchPolicy: "network-only"
, so that polling does not interfere with normal query watching.
@benjamn in #6893 -
Initialize
ObservableQuery
inupdateObservableQuery
even ifskip
istrue
.
@mu29 in #6999 -
Prevent full reobservation of queries affected by optimistic mutation updates, while still delivering results from the cache.
@benjamn in #6854
Improvements
-
In TypeScript, all APIs that take
DocumentNode
parameters now may alternatively takeTypeDocumentNode<Data, Variables>
. This type has the same JavaScript representation but allows the APIs to infer the data and variable types instead of requiring you to specify types explicitly at the call site.
@dotansimha in #6720 -
Bring back an improved form of heuristic fragment matching, by allowing
possibleTypes
to specify subtype regular expression strings, which count as matches if the written result object has all the fields expected for the fragment.
@benjamn in #6901 -
Allow
options.nextFetchPolicy
to be a function that takes the currentFetchPolicy
and returns a new (or the same)FetchPolicy
, makingnextFetchPolicy
more suitable for global use indefaultOptions.watchQuery
.
@benjamn in #6893 -
Implement
useReactiveVar
hook for consuming reactive variables in React components.
@benjamn in #6867 -
Move
apollo-link-persisted-queries
implementation to@apollo/client/link/persisted-queries
. Try running our automated imports transform to handle this conversion, if you're usingapollo-link-persisted-queries
.
@hwillson in #6837 -
Disable feud-stopping logic after any
cache.evict
orcache.modify
operation.
@benjamn in
#6817 and
#6898 -
Throw if
writeFragment
cannot identifyoptions.data
when nooptions.id
provided.
@jcreighton in #6859 -
Provide
options.storage
object tocache.modify
functions, as provided toread
andmerge
functions.
@benjamn in #6991 -
Allow
cache.modify
functions to returndetails.INVALIDATE
(similar todetails.DELETE
) to invalidate the current field, causing affected queries to rerun, even if the field's value is unchanged.
@benjamn in #6991 -
Support non-default
ErrorPolicy
values (that is,"ignore"
and"all"
, in addition to the default value"none"
) for mutations and subscriptions, like we do for queries.
@benjamn in #7003 -
Remove invariant forbidding a
FetchPolicy
ofcache-only
inObservableQuery#refetch
.
@benjamn in ccb0a79a, fixing #6702
Apollo Client 3.1.5
Bug Fixes
Improvements
Apollo Client 3.1.4
Bug Fixes
-
Restrict root object identification to
ROOT_QUERY
(the ID corresponding to the rootQuery
object), allowingMutation
andSubscription
as user-defined types.
@benjamn in #6914 -
Prevent crash when
pageInfo
and emptyedges
are received byrelayStylePagination
.
@fracmak in #6918
Apollo Client 3.1.3
Bug Fixes
- Consider only
result.data
(rather than all properties ofresult
) when settling cache feuds.
@danReynolds in #6777
Improvements
- Provide jscodeshift transform for automatically converting Apollo Client 2.x
import
declarations to use Apollo Client 3.x packages. Instructions.
@dminkovsky and @jcreighton in #6486