@@ -130,8 +130,12 @@ export default class VuexORMApollo {
130130 const model = this . getModel ( state . $name ) ;
131131 const data = model . baseModel . getters ( 'find' ) ( id ) ;
132132
133+ const variables : Data = {
134+ [ model . singularName ] : this . queryBuilder . transformOutgoingData ( data )
135+ } ;
136+
133137 const mutationName = `create${ upcaseFirstLetter ( model . singularName ) } ` ;
134- await this . mutate ( mutationName , data , dispatch , model , true , false ) ;
138+ await this . mutate ( mutationName , variables , dispatch , model , false ) ;
135139
136140 // TODO is this really necessary?
137141 return model . baseModel . getters ( 'find' ) ( id ) ;
@@ -170,9 +174,13 @@ export default class VuexORMApollo {
170174 if ( data ) {
171175 const model = this . getModel ( state . $name ) ;
172176
177+ const variables : Data = {
178+ id : data . id ,
179+ [ model . singularName ] : this . queryBuilder . transformOutgoingData ( data )
180+ } ;
181+
173182 const mutationName = `update${ upcaseFirstLetter ( model . singularName ) } ` ;
174- // TODO whats in data? can we determine addModelToArgs from that?
175- await this . mutate ( mutationName , data , dispatch , model , true , false ) ;
183+ await this . mutate ( mutationName , variables , dispatch , model , false ) ;
176184
177185 // TODO is this really necessary?
178186 return model . baseModel . getters ( 'find' ) ( data . id ) ;
@@ -187,16 +195,16 @@ export default class VuexORMApollo {
187195 * @param {Data } id
188196 * @returns {Promise<void> }
189197 */
190- private async destroy ( { state, dispatch } : ActionParams , { id } : ActionParams ) : Promise < void > {
198+ private async destroy ( { state, dispatch } : ActionParams , { id } : ActionParams ) : Promise < any > {
191199
192200 if ( id ) {
193201 const model = this . getModel ( state . $name ) ;
194202 // TODO use mutate here too
195203 const mutationName = `delete${ upcaseFirstLetter ( model . singularName ) } ` ;
196- const query = this . queryBuilder . buildQuery ( 'mutation' , mutationName , { id } , model ) ;
204+ await this . mutate ( mutationName , { id } , dispatch , model , false )
197205
198- // Send GraphQL Mutation
199- await this . apolloRequest ( query , { where : id } , true ) ;
206+ // TODO what would make sense here?
207+ return true ;
200208 }
201209 }
202210
@@ -209,22 +217,19 @@ export default class VuexORMApollo {
209217 * @param {Model } model
210218 * @returns {Promise<any> }
211219 */
212- private async mutate ( action : string , data : Data | undefined , dispatch : DispatchFunction , model : Model , addModelToArgs : boolean = false , multiple ?: boolean ) : Promise < any > {
213- if ( data ) {
214- const id = data . id ? data . id : undefined ;
215- const variables : Data = {
216- [ model . singularName ] : this . queryBuilder . transformOutgoingData ( data )
217- } ;
220+ private async mutate ( action : string , variables : Data | undefined , dispatch : DispatchFunction , model : Model , multiple ?: boolean ) : Promise < any > {
221+ if ( variables ) {
222+ const id = variables . id ? variables . id : undefined ;
218223
219224 // TODO what about the query fields?
220- const query = this . queryBuilder . buildQuery ( 'mutation' , action , variables , model , undefined , addModelToArgs , multiple ) ;
225+ const query = this . queryBuilder . buildQuery ( 'mutation' , action , variables , model , undefined , multiple ) ;
221226
222- // TODO don't add id for persist
223- if ( id ) variables [ 'id' ] = id ;
224227
225228 // Send GraphQL Mutation
226229 const newData = await this . apolloRequest ( query , variables , true ) ;
227- return this . updateData ( newData , dispatch , data . id ) ;
230+
231+ // TODO: What if there is no id?
232+ return this . updateData ( newData , dispatch , id ) ;
228233 }
229234 }
230235
0 commit comments