Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help "Store reset while query was in flight (not completed in link chain" #12067

Open
wies105 opened this issue Sep 19, 2024 · 1 comment
Labels
🏓 awaiting-team-response requires input from the apollo team

Comments

@wies105
Copy link

wies105 commented Sep 19, 2024

Hello,
I get Store reset while query was in flight (not completed in link chain) after cache.evict called.
I have an Angular 16 Project with "@apollo/client": "^3.11.0",

On Mutation, I will increase the cache.

    return this.apollo.mutate<T>({
      mutation: this.buildDeleteMutationRequest(mutationRequest, id),
      update: (cache, {data}) => this.deletedItemFromCache(cache, classRef, id)
    })
  private deletedItemFromCache<T>(cache: any, classRef: T, id?: number) {
    // Unique identifier for the request to be removed
    const singleRequest = getSingleRequestName(classRef);
    const listRequest = getListRequestName(classRef);
    cache.evict({ id: "ROOT_QUERY", fieldName: listRequest, broadcast: false });
     id && cache.evict({ id: "ROOT_QUERY", fieldName: singleRequest, value: id , broadcast: false });
     try {
      cache.gc({ resetResultCache: true });
     }catch (e : any) {
       console.error(e?.message ? e.message : e);
     }
  }
@wies105
Copy link
Author

wies105 commented Sep 24, 2024

Update:
I have updated my function to check if any qoue in the pipe and run into the same error

  private deletedItemFromCache<T>(cache: any, classRef: T, id?: number) {

    const singleRequest = getSingleRequestName(classRef);
    const listRequest = getListRequestName(classRef);

    this.apollo.client.getObservableQueries("active").forEach((observableQuery: any) => {
      observableQuery.subscribe({
        next: (result: any) => {
          if (result.loading) {
            console.log('Query is in flight:', observableQuery.queryId);
          } else {
            cache.modify({
              id: "ROOT_QUERY",
              fields: {
                [listRequest](existingRefs: any, {readField}: {
                  readField: (fieldName: string, ref: any) => any
                }) {
                  return existingRefs.items?.filter((ref: any) => id !== readField('id', ref)) || existingRefs.filter((ref: any) => id !== readField('id', ref));
                },
                [singleRequest](existingRefs: any, {readField}: {
                  readField: (fieldName: string, ref: any) => any
                }) {
                  return existingRefs.items?.filter(
                    (ref : any) => id === readField('id', ref)
                  ) || existingRefs.filter((ref: any) => id === readField('id', ref));
                }
              }
            });
          }
        }
      })
    });
  }

@bignimbus bignimbus added the 🏓 awaiting-team-response requires input from the apollo team label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

No branches or pull requests

2 participants