Skip to content

Commit 9827f39

Browse files
committed
fix custom mutation variables
1 parent 2667727 commit 9827f39

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8287,6 +8287,7 @@ var VuexORMApollo = /** @class */ (function () {
82878287
VuexORMApollo.prototype.customMutation = function (_a, args) {
82888288
var state = _a.state, dispatch = _a.dispatch;
82898289
return __awaiter(this, void 0, void 0, function () {
8290+
var _this = this;
82908291
var name, model;
82918292
return __generator(this, function (_b) {
82928293
name = args['mutation'];
@@ -8295,7 +8296,9 @@ var VuexORMApollo = /** @class */ (function () {
82958296
// transformOutgoingData()
82968297
Object.keys(args).forEach(function (key) {
82978298
var value = args[key];
8298-
// TODO
8299+
if (value instanceof _this.context.components.Model) {
8300+
args[key] = _this.queryBuilder.transformOutgoingData(value);
8301+
}
82998302
});
83008303
model = this.context.getModel(state.$name);
83018304
return [2 /*return*/, this.mutate(name, args, dispatch, model, false)];

src/vuex-orm-apollo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ export default class VuexORMApollo {
140140
// transformOutgoingData()
141141
Object.keys(args).forEach((key: string) => {
142142
const value: any = args[key];
143-
// TODO
143+
144+
if (value instanceof this.context.components.Model) {
145+
args[key] = this.queryBuilder.transformOutgoingData(value);
146+
}
144147
});
145148

146149
const model = this.context.getModel(state.$name);

test/integration/VuexORMApollo.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ mutation DeleteUser($id: ID!) {
323323

324324
describe('customMutation', () => {
325325
it('sends the correct query to the API', async () => {
326+
const user = store.getters['entities/users/find'](1);
326327
const response = {
327328
data: {
328-
activateUser: {
329+
signupUser: {
329330
__typename: 'user',
330331
id: 1,
331332
name: 'Charlie Brown',
@@ -338,13 +339,14 @@ mutation DeleteUser($id: ID!) {
338339
};
339340

340341
const request = await sendWithMockFetch(response, async () => {
341-
await store.dispatch('entities/users/mutate', { mutation: 'activateUser', id: 1 });
342+
await store.dispatch('entities/users/mutate', { mutation: 'signupUser', user, captchaToken: '15' });
342343
});
343344

344-
expect(request.variables).toEqual({ id: 1 });
345+
expect(request.variables.captchaToken).toEqual('15');
346+
expect(request.variables.user.name).toEqual(user.name);
345347
expect(request.query).toEqual(`
346-
mutation ActivateUser($id: ID!) {
347-
activateUser(id: $id) {
348+
mutation SignupUser($user: UserInput!, $captchaToken: String!) {
349+
signupUser(user: $user, captchaToken: $captchaToken) {
348350
id
349351
name
350352
__typename

0 commit comments

Comments
 (0)