github the-guild-org/apollo-angular apollo-angular@12.0.0

one day ago

Caution

Before upgrading apollo-angular to v12, be sure to read all the breaking changes from @apollo/client v4 that also applies to apollo-angular.

Major Changes

  • #2372
    44ed9a5
    Thanks @jerelmiller! - Namespaced types

    Before:

    import type {
      MutationOptionsAlone,
      QueryOptionsAlone,
      SubscriptionOptionsAlone,
      WatchQueryOptions,
      WatchQueryOptionsAlone,
    } from 'apollo-angular';
    import type { BatchOptions, Options } from 'apollo-angular/http';
    
    type AllTypes =
      | Options
      | BatchOptions
      | MutationOptionsAlone
      | QueryOptionsAlone
      | SubscriptionOptionsAlone
      | WatchQueryOptions
      | WatchQueryOptionsAlone;

    After:

    import type { Apollo, Mutation, Query, Subscription } from 'apollo-angular';
    import type { HttpBatchLink, HttpLink } from 'apollo-angular/http';
    
    type AllTypes =
      | HttpLink.Options
      | HttpBatchLink.Options
      | Mutation.MutateOptions
      | Query.FetchOptions
      | Subscription.SubscribeOptions
      | Apollo.WatchQueryOptions
      | Query.WatchOptions;
  • #2372
    bdc93df
    Thanks @jerelmiller! - httpHeaders is a class

    Migrate your code like so:

    - const link = httpHeaders();
    + const link = new HttpHeadersLink();
  • #2372
    8c0b7f0
    Thanks @jerelmiller! - Move useZone option into subscription
    options

    - const obs = apollo.subscribe(options, { useZone: false });
    + const obs = apollo.subscribe({ ...options, useZone: false });
  • #2372
    b9c62a5
    Thanks @jerelmiller! - Combined parameters of Query,
    Mutation and Subscription classes generated via codegen

    Migrate your code like so:

    class MyComponent {
      myQuery = inject(MyQuery);
      myMutation = inject(MyMutation);
      mySubscription = inject(MySubscription);
    
      constructor() {
    -    myQuery.watch({ myVariable: 'foo' }, { fetchPolicy: 'cache-and-network' });
    +    myQuery.watch({ variables: { myVariable: 'foo' }, fetchPolicy: 'cache-and-network' })
    
    -    myMutation.mutate({ myVariable: 'foo' }, { errorPolicy: 'ignore' });
    +    myMutation.mutate({ variables: { myVariable: 'foo' }, errorPolicy: 'ignore' });
    
    -    mySubscription.subscribe({ myVariable: 'foo' }, { fetchPolicy: 'network-only' });
    +    mySubscription.subscribe({ variables: { myVariable: 'foo' }, fetchPolicy: 'network-only' });
      }
    }

Minor Changes

  • #2379
    7e4a609
    Thanks @PowerKiKi! - New onlyComplete() helper to filter only
    complete results

    If you use this, you should probably combine it with
    notifyOnNetworkStatusChange.
    This tells @apollo/client to not emit the first partial result, so apollo-angular does not
    need to filter it out. The overall behavior is identical, but it saves some CPU cycles.

    So something like this:

    apollo
      .watchQuery({
        query: myQuery,
        notifyOnNetworkStatusChange: false, // Adding this will save CPU cycles
      })
      .valueChanges.pipe(onlyComplete())
      .subscribe(result => {
        // Do something with complete result
      });

Patch Changes

Don't miss a new apollo-angular release

NewReleases is sending notifications on new releases.