You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
Hi, I'm trying to write a link which will let the client know how many running queries are still running (for testing). I wrote following on, but the issue there is that if I run n consecutive queries of a same name but with different parameters, only the last query will receive "complete" callback. Any idea what is going on? I used your "Dedupe" link as a base for this
import{ApolloLink,FetchResult,NextLink,Observable,Operation,}from'apollo-link-core';importApolloClientfrom'apollo-client';import{print}from'graphql/language/printer';/* * Expects context to contain the forceFetch field if no dedup */exportclassSpyLinkextendsApolloLink{privateclient: ()=>ApolloClient;privateinFlightRequestObservables: {[key: string]: Observable<FetchResult>;};constructor(client: ()=>ApolloClient){super();this.inFlightRequestObservables={};this.client=client;}/** Will wait for all queries to finish running */publicasyncwait(){returnnewPromise((resolve)=>{constcheck=()=>{if(Object.getOwnPropertyNames(this.inFlightRequestObservables).length===0){resolve();}else{setTimeout(check,5);}};check();});}publicrequest(operation: Operation,forward: NextLink,): Observable<FetchResult>{// we need to add it like this, brutally as we have no access ton client on individual linksif(!(this.client()asany).spyLink){(this.client()asany).spyLink=this;}constkey=this.getKey(operation);if(!this.inFlightRequestObservables[key]){this.inFlightRequestObservables[key]=forward(operation);}returnnewObservable<FetchResult>((observer)=>this.inFlightRequestObservables[key].subscribe({next: observer.next.bind(observer),error: (error)=>{deletethis.inFlightRequestObservables[key];observer.error(error);},complete: ()=>{deletethis.inFlightRequestObservables[key];observer.complete();},}),);}privategetKey(operation: Operation){return`${print(operation.query)}|${JSON.stringify(operation.variables,)}|${operation.operationName}`;}}
The text was updated successfully, but these errors were encountered:
Solves the problem obviously as only the query itself is now the key. Works ... as long as queries are returned in the same order as requested ... which in a lot of cases will NOT.
Is operations.variables an array @tomitrescak? otherwise your JSON.stringify is dependent on the order of entries in a hash, which I don't think is guaranteed.
Hi, I'm trying to write a link which will let the client know how many running queries are still running (for testing). I wrote following on, but the issue there is that if I run n consecutive queries of a same name but with different parameters, only the last query will receive "complete" callback. Any idea what is going on? I used your "Dedupe" link as a base for this
The text was updated successfully, but these errors were encountered: