@@ -14,7 +14,7 @@ import {
1414 Observable ,
1515 Operation ,
1616 FetchResult ,
17- NextLink
17+ NextLink ,
1818} from "apollo-link" ;
1919import { Observer } from "zen-observable-ts" ;
2020
@@ -58,7 +58,7 @@ export default class MutationQueueLink extends ApolloLink {
5858 this . inProcess = true ;
5959 this . log ( "[PROCESSING] -" , toRequestKey ( operation ) ) ;
6060 forward ( operation ) . subscribe ( {
61- next : result => {
61+ next : ( result ) => {
6262 this . inProcess = false ;
6363 observer . next ( result ) ;
6464 this . log ( "[NEXT] -" , toRequestKey ( operation ) ) ;
@@ -67,7 +67,7 @@ export default class MutationQueueLink extends ApolloLink {
6767 this . processOperation ( this . opQueue . shift ( ) ) ;
6868 }
6969 } ,
70- error : error => {
70+ error : ( error ) => {
7171 this . inProcess = false ;
7272 observer . error ( error ) ;
7373 this . log ( "[ERROR] -" , toRequestKey ( operation ) , error ) ;
@@ -76,26 +76,26 @@ export default class MutationQueueLink extends ApolloLink {
7676 this . processOperation ( this . opQueue . shift ( ) ) ;
7777 }
7878 } ,
79- complete : observer . complete . bind ( observer )
79+ complete : observer . complete . bind ( observer ) ,
8080 } ) ;
8181 }
8282
8383 private cancelOperation ( entry : OperationQueueEntry ) {
84- this . opQueue = this . opQueue . filter ( e => e !== entry ) ;
84+ this . opQueue = this . opQueue . filter ( ( e ) => e !== entry ) ;
8585 }
8686
8787 private enqueue ( entry : OperationQueueEntry ) {
8888 this . log ( "[ENQUEUE] -" , toRequestKey ( entry . operation ) ) ;
8989 this . opQueue . push ( entry ) ;
9090 }
9191
92- public request ( operation : Operation , forward : NextLink ) : Observable < FetchResult > | null {
92+ public request (
93+ operation : Operation ,
94+ forward : NextLink
95+ ) : Observable < FetchResult > | null {
9396 // Enqueue all mutations unless manually skipped.
94- if (
95- operation . toKey ( ) . includes ( '"operation":"mutation"' ) &&
96- ! operation . getContext ( ) . skipQueue
97- ) {
98- return new Observable ( observer => {
97+ if ( isMutation ( operation ) && ! operation . getContext ( ) . skipQueue ) {
98+ return new Observable ( ( observer ) => {
9999 const operationEntry = { operation, forward, observer } ;
100100 if ( ! this . inProcess ) {
101101 this . processOperation ( operationEntry ) ;
@@ -109,3 +109,11 @@ export default class MutationQueueLink extends ApolloLink {
109109 }
110110 }
111111}
112+
113+ function isMutation ( operation : Operation ) {
114+ return operation . query . definitions . some (
115+ ( definition ) =>
116+ definition . kind === "OperationDefinition" &&
117+ definition . operation === "mutation"
118+ ) ;
119+ }
0 commit comments