github apollographql/apollo-client v3.3.0
3.3.0

latest releases: v3.10.4, v3.10.3, v3.10.2...
3 years ago

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 in ApolloClient constructor.
    @kamilkisiela in #7161

  • Provide default empty cache object for root IDs like ROOT_QUERY, to avoid differences in behavior before/after ROOT_QUERY data has been written into InMemoryCache.
    @benjamn in #7100

  • Cancel queryInfo.notifyTimeout in QueryInfo#markResult to prevent unnecessary network requests when using a FetchPolicy of cache-and-network or network-only in a React component with multiple useQuery calls.
    @benjamn in #7347

Potentially breaking changes

  • Ensure cache.readQuery and cache.readFragment always return TData | null, instead of throwing MissingFieldError exceptions when missing fields are encountered.
    @benjamn in #7098

    Since this change converts prior exceptions to null returns, and since null was already a possible return value according to the TData | null return type, we are confident this change will be backwards compatible (as long as null was properly handled before).

  • HttpLink will now automatically strip any unused variables 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 passing includeUnusedVariables: true to the HttpLink constructor (which is typically passed as options.link to the ApolloClient constructor).
    @benjamn in #7127

  • Ensure MockLink (used by MockedProvider) returns mock configuration errors (e.g. No more mocked responses for the query ...) through the Link's Observable, instead of throwing them. These errors are now available through the error property of a result.
    @hwillson in #7110

    Returning 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 on MockLink's throwing exception approach. If you want to change this functionality, you can define custom error handling through MockLink.setOnError.

  • Unsubscribing the last observer from an ObservableQuery will once again unsubscribe from the underlying network Observable 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 and ModifiableWatchQueryOptions interface supertypes have been eliminated, and their fields are now defined by QueryOptions.
    @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 the merge: true and merge: 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 have keyArgs configured will now invalidate only the field value with matching key arguments, rather than invalidating all field values that share the same field name. If keyArgs 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 and useLazyQuery will now provide a result.previousData property, which can be useful when a network request is pending and result.data is undefined, since result.previousData can be rendered instead of rendering an empty/loading state.
    @hwillson in #7082

  • Passing validate: true to the SchemaLink constructor will enable validation of incoming queries against the local schema before execution, returning validation errors in result.errors, just like a non-local GraphQL endpoint typically would.
    @amannn in #7094

  • Allow optional arguments in keyArgs: [...] arrays for InMemoryCache field policies.
    @benjamn in #7109

  • Avoid registering QueryPromise when skip is true during server-side rendering.
    @izumin5210 in #7310

  • ApolloCache objects (including InMemoryCache) may now be associated with or disassociated from individual reactive variables by calling reactiveVar.attachCache(cache) and/or reactiveVar.forgetCache(cache).
    @benjamn in #7350

Don't miss a new apollo-client release

NewReleases is sending notifications on new releases.