question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apollo Angular 4.0 `QueryRef.fetchMore` parameter typings remove `updateQuery` property

See original GitHub issue

Describe the bug Upgrading from apollo-angular@3.0.1 to apollo-angular@4.0.1 produces TS2345 error on code which passes an updateQuery property to the fetchMoreOptions parameter of a QueryRef.fetchMorecall.

To Reproduce Previously, the QueryRef.fetchMore fetchMoreOptions parameter was typed with FetchMoreQueryOptions & FetchMoreOptions but Apollo Angular 4 removed FetchMoreOptions and with it the updateQuery property on the parameter.

Expected behavior The method signature should not change, since the underlying Apollo Client ObservableQuery.fetchMore method still has updateQuery in its signature.

Environment:

├── @angular/cli@14.1.3 
├── @angular/core@14.1.3 
├── @apollo/client@3.6.8 
├── apollo-angular@4.0.1 
├── barrel-maintainer@1.5.3
├── graphql@16.5.0 
└── typescript@4.7.4 

Additional context That pretty much sums it up.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KeithGillettecommented, Oct 26, 2022

Hi, @alfaproject — Well, so far as I can see, updateQuery is still available on ObservableQuery in Apollo Client 3.x and not marked in the code as deprecated, so I think you could continue using it with Apollo Angular 4 with suitable @ts-ignore comments, but since I haven’t seen anything to contradict the statements from the Apollo team that I linked to in my last message indicating that updateQuery will be removed in Apollo Client 4 and the fetchMore documentation has been updated to remove reference to updateQuery in favor of field policies, I do think that you’ll eventually have to update your code to use merge functions on field policies, one for each field that needs your dynamic updateQuery logic. Note that field policy merge functions can be generic with respect to the data type, just as your updateQuery function example is.

1reaction
alfaprojectcommented, Oct 26, 2022

@KeithGillette I have a dynamic helper that creates a dynamic updateQuery to avoid repetition, something like this:

      updateQuery: (prev, { fetchMoreResult }) => {
        if (!fetchMoreResult) {
          return prev;
        }

        const newEdges = fetchMoreResult[this.connectionFieldName].edges;
        if (newEdges.length === 0) {
          return prev;
        }

        return {
          [this.connectionFieldName]: {
            ...fetchMoreResult[this.connectionFieldName],
            edges:
              this.direction === Direction.ASCENDING
                ? [...prev[this.connectionFieldName].edges, ...newEdges]
                : [...newEdges, ...prev[this.connectionFieldName].edges],
          },
        };
      },

Are you telling me that we now need to go to our cache adaptor and add type policy for each individual connection. We have hundreds of them and each one is ‘owned’ by a particular service which is agnostic to the cache o.o

Read more comments on GitHub >

github_iconTop Results From Across the Web

[typescript] the "query" parameter in fetchMore should not be ...
When using Query with fetchMore for pagination, typescript complains that the argument with just variables and updateQuery is not assignable ...
Read more >
TypeScript with Apollo Client - Apollo GraphQL Docs
By default, the type parameters for fetchMore are the same as those for useQuery . Because both fetchMore and useQuery encapsulate a query...
Read more >
Pagination – Angular - GraphQL Code Generator
Apollo lets you do pagination with a method called fetchMore . You need to specify what query and variables to use for the...
Read more >
Running Apollo Angular watchQuery() with different variables ...
I just solved a similar issue you were having and the trick was to call this._querySubscription.refetch(newVariables) .
Read more >
Getting started with Apollo + GraphQL in Angular - Briebug Blog
Apollo is an open source GraphQL client built for Javascript and includes comprehensive integrations with Angular, React and Vue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found