@@ -103,15 +103,15 @@ export default class VuexORMApollo {
103103 * @param {any } dispatch
104104 * @returns {Promise<void> }
105105 */
106- private async fetch ( { state, dispatch, filter } : ActionParams ) {
106+ private async fetch ( { state, dispatch } : ActionParams , filter : ActionParams ) {
107107 // When the filter contains an id, we query in singular mode
108- const multiple : boolean = ! ( filter && filter . get ( 'id' ) ) ;
108+ const multiple : boolean = ! ( filter && filter [ 'id' ] ) ;
109109 const model : Model = this . getModel ( state . $name ) ;
110110 const name : string = `${ multiple ? model . pluralName : model . singularName } ` ;
111111 const query = this . queryBuilder . buildQuery ( 'query' , name , filter , model . singularName ) ;
112112
113113 // Send the request to the GraphQL API
114- const data = await this . apolloRequest ( query ) ;
114+ const data = await this . apolloRequest ( query , filter ) ;
115115
116116 // Insert incoming data into the store
117117 await this . insertData ( data , dispatch ) ;
@@ -196,10 +196,7 @@ export default class VuexORMApollo {
196196 const query = this . queryBuilder . buildQuery ( 'mutation' , mutationName , { id } , model ) ;
197197
198198 // Send GraphQL Mutation
199- await this . apolloClient . mutate ( {
200- mutation : query ,
201- variables : { where : id }
202- } ) ;
199+ await this . apolloRequest ( query , { where : id } , true ) ;
203200 }
204201 }
205202
@@ -225,27 +222,27 @@ export default class VuexORMApollo {
225222 if ( id ) variables [ 'id' ] = id ;
226223
227224 // Send GraphQL Mutation
228- const response = await this . apolloClient . mutate ( {
229- mutation : query ,
230- variables
231- } ) ;
232-
233- // Insert incoming data into the store
234- const newData = this . queryBuilder . transformIncomingData ( response . data as Data , true ) ;
225+ const newData = await this . apolloRequest ( query , variables , true ) ;
235226 return this . updateData ( newData , dispatch , data . id ) ;
236227 }
237228 }
238229
239230 /**
240- * Sends a query to the GraphQL API via apollo
231+ * Sends a request to the GraphQL API via apollo
241232 * @param query
242233 * @returns {Promise<Data> }
243234 */
244- private async apolloRequest ( query : any ) : Promise < Data > {
245- const response = await ( this . apolloClient ) . query ( { query } ) ;
235+ private async apolloRequest ( query : any , variables ?: Arguments , mutation :boolean = false ) : Promise < Data > {
236+ let response ;
237+
238+ if ( mutation ) {
239+ response = await ( this . apolloClient ) . mutate ( { mutation : query , variables } ) ;
240+ } else {
241+ response = await ( this . apolloClient ) . query ( { query, variables } ) ;
242+ }
246243
247244 // Transform incoming data into something useful
248- return this . queryBuilder . transformIncomingData ( response . data ) ;
245+ return this . queryBuilder . transformIncomingData ( response . data as Data , mutation ) ;
249246 }
250247
251248 /**
0 commit comments