Skip to content

Commit 1ba9af6

Browse files
committed
Finishing push
1 parent 3deec4f commit 1ba9af6

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8349,6 +8349,9 @@ var QueryBuilder = /** @class */ (function () {
83498349
throw new Error('No ID given.');
83508350
args = { id: id };
83518351
}
8352+
else if (prefix === 'update') {
8353+
args['id'] = id;
8354+
}
83528355
var signature = this.buildArguments(args, true, false, true);
83538356
var field = this.buildField(model, false, args, true, model, name, true);
83548357
var query = "\n mutation " + name + signature + " {\n " + field + "\n }\n ";
@@ -8552,13 +8555,15 @@ var VuexORMApollo = /** @class */ (function () {
85528555
return __generator(this, function (_c) {
85538556
switch (_c.label) {
85548557
case 0:
8558+
if (!id) return [3 /*break*/, 2];
85558559
model = this.getModel(state.$name);
85568560
data = model.baseModel.getters('find')(id);
8557-
return [4 /*yield*/, this.mutate('create', data, dispatch, this.getModel(state.$name))];
8561+
return [4 /*yield*/, this.mutate('create', data, dispatch, model)];
85588562
case 1:
85598563
_c.sent();
85608564
// TODO is this really necessary?
85618565
return [2 /*return*/, model.baseModel.getters('find')(id)];
8566+
case 2: return [2 /*return*/];
85628567
}
85638568
});
85648569
});
@@ -8574,8 +8579,19 @@ var VuexORMApollo = /** @class */ (function () {
85748579
var state = _a.state, dispatch = _a.dispatch;
85758580
var data = _b.data;
85768581
return __awaiter(this, void 0, void 0, function () {
8582+
var model;
85778583
return __generator(this, function (_c) {
8578-
return [2 /*return*/, this.mutate('update', data, dispatch, this.getModel(state.$name))];
8584+
switch (_c.label) {
8585+
case 0:
8586+
if (!data) return [3 /*break*/, 2];
8587+
model = this.getModel(state.$name);
8588+
return [4 /*yield*/, this.mutate('update', data, dispatch, model)];
8589+
case 1:
8590+
_c.sent();
8591+
// TODO is this really necessary?
8592+
return [2 /*return*/, model.baseModel.getters('find')(data.id)];
8593+
case 2: return [2 /*return*/];
8594+
}
85798595
});
85808596
});
85818597
};

src/queryBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ export default class QueryBuilder {
278278
if (prefix === 'delete') {
279279
if (!id) throw new Error('No ID given.');
280280
args = { id };
281+
} else if (prefix === 'update') {
282+
args['id'] = id;
281283
}
282284

283285
const signature: string = this.buildArguments(args, true, false, true);

src/vuex-orm-apollo.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@ export default class VuexORMApollo {
119119
* @returns {Promise<void>}
120120
*/
121121
private async persist ({ state, dispatch }: ActionParams, { id }: ActionParams) {
122-
const model = this.getModel(state.$name);
123-
const data = model.baseModel.getters('find')(id);
122+
if (id) {
123+
const model = this.getModel(state.$name);
124+
const data = model.baseModel.getters('find')(id);
124125

125-
await this.mutate('create', data, dispatch, this.getModel(state.$name));
126+
await this.mutate('create', data, dispatch, model);
126127

127-
// TODO is this really necessary?
128-
return model.baseModel.getters('find')(id);
128+
// TODO is this really necessary?
129+
return model.baseModel.getters('find')(id);
130+
}
129131
}
130132

131133
/**
@@ -136,7 +138,14 @@ export default class VuexORMApollo {
136138
* @returns {Promise<Data | {}>}
137139
*/
138140
private async push ({ state, dispatch }: ActionParams, { data }: ActionParams) {
139-
return this.mutate('update', data, dispatch, this.getModel(state.$name));
141+
if (data) {
142+
const model = this.getModel(state.$name);
143+
144+
await this.mutate('update', data, dispatch, model);
145+
146+
// TODO is this really necessary?
147+
return model.baseModel.getters('find')(data.id);
148+
}
140149
}
141150

142151
/**

test/unit/QueryBuilder.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ mutation createUser($user: UserInput!) {
357357
query = QueryBuilder.prettify(query.loc.source.body);
358358

359359
expect(query).toEqual(`
360-
mutation updateUser($user: UserInput!) {
361-
updateUser(user: $user) {
360+
mutation updateUser($user: UserInput!, $id: ID!) {
361+
updateUser(user: $user, id: $id) {
362362
id
363363
name
364364
profiles {

0 commit comments

Comments
 (0)