Skip to content

@apollo/client@4.0.0-alpha.23

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 18 Jun 21:22
· 6 commits to main since this release
44645d2

Major Changes

  • #12712 bbb2b61 Thanks @jerelmiller! - An error is now thrown when trying to call fetchMore on a cache-only query.

  • #12712 bbb2b61 Thanks @jerelmiller! - cache-only queries are no longer refetched when calling client.reFetchObservableQueries when includeStandby is true.

  • #12705 a60f411 Thanks @jerelmiller! - cache-only queries will now initialize with loading: false and networkStatus: NetworkStatus.ready when there is no data in the cache.

    This means useQuery will no longer render a short initial loading state before rendering loading: false and ObservableQuery.getCurrentResult() will now return loading: false immediately.

  • #12712 bbb2b61 Thanks @jerelmiller! - cache-only queries are now excluded from client.refetchQueries in all situations. cache-only queries affected by updateCache are also excluded from refetchQueries when onQueryUpdated is not provided.

  • #12681 b181f98 Thanks @jerelmiller! - Changing most options when rerendering useQuery will no longer trigger a reobserve which may cause network fetches. Instead, the changed options will be applied to the next cache update or fetch.

    Options that now trigger a reobserve when changed between renders are:

    • query
    • variables
    • skip
    • Changing fetchPolicy to or from standby
  • #12714 0e39469 Thanks @phryneas! - Rework option handling for fetchMore.

    • Previously, if the query option was specified, no options would be inherited
      from the underlying ObservableQuery.
      Now, even if query is specified, all unspecified options except for variables will be inherited from the underlying ObservableQuery.
    • If query is not specified, variables will still be shallowly merged with the variables of the underlying ObservableQuery. If a query option is specified, the variables passed to fetchMore are used instead.
    • errorPolicy of fetchMore will now always default to "none" instead of inherited from the ObservableQuery options. This can prevent accidental cache writes of partial data for a paginated query. To opt into receive partial data that may be written to the cache, pass an errorPolicy to fetchMore to override the default.
  • #12700 8e96e08 Thanks @phryneas! - Added a new Streaming type that will mark data in results while dataStatus
    is "streaming".

    Streaming<TData> defaults to TData, but can be overwritten in userland to
    integrate with different codegen dialects.

    You can override this type globally - this example shows how to override it
    with DeepPartial<TData>:

    import { HKT, DeepPartial } from "@apollo/client/utilities";
    
    type StreamingOverride<TData> = DeepPartial<TData>;
    
    interface StreamingOverrideHKT extends HKT {
      return: StreamingOverride<this["arg1"]>;
    }
    
    declare module "@apollo/client" {
      export interface TypeOverrides {
        Streaming: StreamingOverrideHKT;
      }
    }
  • #12499 ce35ea2 Thanks @phryneas! - Enable React compiler for hooks in ESM builds.

  • #12704 45dba43 Thanks @jerelmiller! - The ErrorResponse object passed to the disable and retry callback options provided to createPersistedQueryLink no longer provides separate graphQLErrors and networkError properties and instead have been combined to a single error property of type ErrorLike.

    // The following also applies to the `retry` function since it has the same signature
    createPersistedQueryLink({
    - disable: ({ graphQLErrors, networkError }) => {
    + disable: ({ error }) => {
    -   if (graphQLErrors) {
    +   if (CombinedGraphQLErrors.is(error)) {
          // ... handle GraphQL errors
        }
    
    -   if (networkError) {
    +   if (error) {
          // ... handle link errors
        }
    
        // optionally check for a specific kind of error
    -   if (networkError) {
    +   if (ServerError.is(error)) {
          // ... handle a server error
        }
    });

    The response property has also been renamed to result.

    createPersistedQueryLink({
    -  disable: ({ response }) => {
    +  disable: ({ result }) => {
          // ... handle GraphQL errors
        }
      }
    });
  • #12712 bbb2b61 Thanks @jerelmiller! - cache-only queries no longer poll when a pollInterval is set. Instead a warning is now emitted that polling has no effect. If the fetchPolicy is changed to cache-only after polling is already active, polling is stopped.

  • #12704 45dba43 Thanks @jerelmiller! - The response property in onError link has been renamed to result.

    - onError(({ response }) => {
    + onError(({ result }) => {
        // ...
    });
  • #12715 0be0b3f Thanks @phryneas! - All links are now available as classes. The old creator functions have been deprecated.

    Please migrate these function calls to class creations:

    import {
    - setContext
    + SetContextLink
    } from "@apollo/client/link/context"
    
    -const link = setContext(...)
    +const link = new SetContextLink(...)
    import {
    - createHttpLink
    + HttpLink
    } from "@apollo/client/link/http"
    
    -const link = createHttpLink(...)
    +const link = new HttpLink(...)
    import {
    - createPersistedQueryLink
    + PersistedQueryLink
    } from "@apollo/client/link/persisted-queries"
    
    -const link = createPersistedQueryLink(...)
    +const link = new PersistedQueryLink(...)
    import {
    - removeTypenameFromVariables
    + RemoveTypenameFromVariablesLink
    } from "@apollo/client/link/remove-typename"
    
    -const link = removeTypenameFromVariables(...)
    +const link = new RemoveTypenameFromVariablesLink(...)

Minor Changes

  • #12711 f730f83 Thanks @jerelmiller! - Add an extensions property to CombinedGraphQLErrors to capture any extensions from the original response.

  • #12700 8e96e08 Thanks @phryneas! - The callback function that can be passed to the ApolloClient.mutate
    refetchQueries option will now receive a FormattedExecutionResult with an
    additional dataState option that describes if the result is "streaming"
    or "complete".
    This indicates whether the data value is of type

    • Unmasked<TData> (if "complete")
    • Streaming<Unmasked<TData>> (if "streaming")
  • #12714 0e39469 Thanks @phryneas! - Allow passing errorPolicy option to fetchMore and change default value to "none".

  • #12714 0e39469 Thanks @phryneas! - The FetchMoreQueryOptions type has been inlined into FetchMoreOptions, and
    FetchMoreQueryOptions has been removed.

  • #12700 8e96e08 Thanks @phryneas! - Prioritize usage of FormattedExecutionResult over FetchResult where applicable.

    Many APIs used FetchResult in place of FormattedExecutionResult, which could
    cause inconsistencies.

    • FetchResult is now used to refer to an unhandled "raw" result as returned from
      a link.
      This can also include incremental results that use a different format.
    • FormattedExecutionResult from the graphql package is now used to represent
      the execution of a standard GraphQL request without incremental results.

    If your custom links access the data property, you might need to first check if
    the result is a standard GraphQL result by using the isFormattedExecutionResult
    helper from @apollo/client/utilities.

  • #12700 8e96e08 Thanks @phryneas! - The mutationResult option passed to the updateQueries callback now has an
    additional property, dataState with possible values of "complete" and "streaming".
    This indicates whether the data value is of type

    • Unmasked<TData> (if "complete")
    • Streaming<Unmasked<TData>> (if "streaming")

Patch Changes

  • #12709 9d42e2a Thanks @phryneas! - Remove these incremental-format-specific types:

    • ExecutionPatchIncrementalResult
    • ExecutionPatchInitialResult
    • ExecutionPatchResult
    • IncrementalPayload
    • Path
  • #12677 94e58ed Thanks @jerelmiller! - Downgrade minimum supported rxjs peer dependency version to 7.3.0.

  • #12709 9d42e2a Thanks @phryneas! - Slightly rework multipart response parsing.

    This removes last incremental-protocol-specific details from HttpLink and BatchHttpLink.

  • #12700 8e96e08 Thanks @phryneas! - The incremental delivery (@defer support) implementation is now pluggable.

    ApolloClient now per default ships without an incremental format implementation
    and allows you to swap in the format that you want to use.

    Usage looks like this:

    import {
      // this is the default
      NotImplementedHandler,
      // this implements the `@defer` transport format that ships with Apollo Router
      Defer20220824Handler,
      // this implements the `@defer` transport format that ships with GraphQL 17.0.0-alpha.2
      GraphQL17Alpha2Handler,
    } from "@apollo/client/incremental";
    
    const client = new ApolloClient({
      cache: new InMemoryCache({
        /*...*/
      }),
      link: new HttpLink({
        /*...*/
      }),
      incrementalHandler: new Defer20220824Handler(),
    });

    We will add handlers for other response formats that can be swapped this way
    during the lifetime of Apollo Client 4.0.