Skip to content

Commit 3c53fda

Browse files
committed
Add better multiple detectionn for custom mutations
1 parent c371c1a commit 3c53fda

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10232,16 +10232,17 @@ var Action = /** @class */ (function () {
1023210232
* @param {Data | undefined} variables Variables to send with the mutation
1023310233
* @param {Function} dispatch Vuex Dispatch method for the model
1023410234
* @param {Model} model The model this mutation affects.
10235+
* @param {boolean} multiple Tells if we're requesting a single record or multiple.
1023510236
* @returns {Promise<any>}
1023610237
*/
10237-
Action.mutation = function (name, variables, dispatch, model) {
10238+
Action.mutation = function (name, variables, dispatch, model, multiple) {
10239+
if (multiple === void 0) { multiple = false; }
1023810240
return __awaiter$2(this, void 0, void 0, function () {
10239-
var multiple, query, newData, insertedData;
10241+
var query, newData, insertedData;
1024010242
return __generator$2(this, function (_a) {
1024110243
switch (_a.label) {
1024210244
case 0:
1024310245
if (!variables) return [3 /*break*/, 4];
10244-
multiple = false;
1024510246
query = QueryBuilder.buildQuery('mutation', model, name, variables, multiple);
1024610247
return [4 /*yield*/, Context.getInstance().apollo.request(model, query, variables, true)];
1024710248
case 1:
@@ -10559,7 +10560,7 @@ var Mutate = /** @class */ (function (_super) {
1055910560
// transformOutgoingData()
1056010561
this.transformArgs(args);
1056110562
// Send the mutation
10562-
return [2 /*return*/, Action.mutation(mutationName, args, dispatch, model)];
10563+
return [2 /*return*/, Action.mutation(mutationName, args, dispatch, model, !args['id'])];
1056310564
});
1056410565
});
1056510566
};
@@ -10742,6 +10743,7 @@ var Push = /** @class */ (function (_super) {
1074210743
* @param {any} state The Vuex state
1074310744
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
1074410745
* @param {Arguments} data New data to save
10746+
* @param {Arguments} args Additional arguments
1074510747
* @returns {Promise<Data>} The updated record
1074610748
*/
1074710749
Push.call = function (_a, _b) {

src/actions/action.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ export default class Action {
2121
* @param {Data | undefined} variables Variables to send with the mutation
2222
* @param {Function} dispatch Vuex Dispatch method for the model
2323
* @param {Model} model The model this mutation affects.
24+
* @param {boolean} multiple Tells if we're requesting a single record or multiple.
2425
* @returns {Promise<any>}
2526
*/
2627
protected static async mutation (name: string, variables: Data | undefined, dispatch: DispatchFunction,
27-
model: Model): Promise<any> {
28+
model: Model, multiple: boolean = false): Promise<any> {
2829
if (variables) {
29-
// FIXME for custom mutations multiple could be true. Maybe check for an ID?
30-
const multiple = false;
3130
const query = QueryBuilder.buildQuery('mutation', model, name, variables, multiple);
3231

3332
// Send GraphQL Mutation

src/actions/mutate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export default class Mutate extends Action {
2121
this.transformArgs(args);
2222

2323
// Send the mutation
24-
return Action.mutation(mutationName, args, dispatch, model);
24+
return Action.mutation(mutationName, args, dispatch, model, !args['id']);
2525
}
2626
}

src/actions/push.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class Push extends Action {
1010
* @param {any} state The Vuex state
1111
* @param {DispatchFunction} dispatch Vuex Dispatch method for the model
1212
* @param {Arguments} data New data to save
13+
* @param {Arguments} args Additional arguments
1314
* @returns {Promise<Data>} The updated record
1415
*/
1516
public static async call ({ state, dispatch }: ActionParams, { data, args }: ActionParams): Promise<Data> {

0 commit comments

Comments
 (0)