Skip to content

Releases: apollographql/apollo-client

v4.0.0-alpha.4

24 Mar 19:32
3f384a9
Compare
Choose a tag to compare
v4.0.0-alpha.4 Pre-release
Pre-release

Major Changes

  • #12463 3868df8 Thanks @jerelmiller! - ObservableQuery.setOptions has been removed as it was an alias of reobserve. Prefer using reobserve directly instead.

    const observable = client.watchQuery(options);
    
    // Use reobserve to set new options and reevaluate the query
    - observable.setOptions(newOptions);
    + observable.reobserve(newOptions);

    As a result of this change, reobserve has been marked for public use and is no longer considered an internal API. The newNetworkStatus argument has been removed to facilitate this change.

  • #12470 d32902f Thanks @phryneas! - ssrMode, ssrForceFetchDelay and disableNetworkFetches have been reworked:

    Previously, a ObservableQuery created by client.query or client.watchQuery
    while one of those were active would permanently be changed from a fetchPolicy
    of "network-only" or "cache-and-network" to "cache-first", and stay that way
    even long after disableNetworkFetches would have been deactivated.

    Now, the ObservableQuery will keep their original fetchPolicy, but queries
    made during disableNetworkFetches will just apply the fetchPolicy replacement
    at request time, just for that one request.

    ApolloClient.disableNetworkFetches has been renamed to ApolloClient.prioritizeCacheValues to better reflect this behaviour.

  • #12465 a132163 Thanks @jerelmiller! - Flatten out React hook types. As a result, the base types have been removed. Prefer using the hook types instead. Removed types include:

    • BaseMutationOptions
    • BaseQueryOptions
    • BaseSubscriptionOptions
    • ObservableQueryFields
    • MutationSharedOptions
    • QueryFunctionOptions
  • #12463 3868df8 Thanks @jerelmiller! - useQuery no longer returns reobserve as part of its result. It was possible to use reobserve to set new options on the underlying ObservableQuery instance which differed from the options passed to the hook. This could result in unexpected results. Instead prefer to rerender the hook with new options.

Patch Changes

  • #12465 a132163 Thanks @jerelmiller! - Rename all React hook result types and options. These types have all moved under a namespace that matches the hook name. For example, useQuery exports useQuery.Options and useQuery.Result types. As such, the old hook types have been deprecated and will be removed in v5.

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