Skip to content

Commit cd35b97

Browse files
committed
Upgrade to vuex-orm 0.24.4
1 parent 4f5f757 commit cd35b97

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7801,11 +7801,11 @@ var QueryBuilder = /** @class */ (function () {
78017801
*
78027802
* Omits relations and id fields.
78037803
*
7804+
* @param model
78047805
* @param {Data} data
78057806
* @returns {Data}
78067807
*/
7807-
QueryBuilder.prototype.transformOutgoingData = function (data) {
7808-
var model = this.getModel(data.$self().entity);
7808+
QueryBuilder.prototype.transformOutgoingData = function (model, data) {
78097809
var relations = model.getRelations();
78107810
var returnValue = {};
78117811
Object.keys(data).forEach(function (key) {
@@ -8239,6 +8239,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod
82398239
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
82408240
}
82418241
};
8242+
var inflection$3 = require('inflection');
82428243
/**
82438244
* Plugin class
82448245
*/
@@ -8347,7 +8348,7 @@ var VuexORMApollo = /** @class */ (function () {
83478348
model = this.context.getModel(state.$name);
83488349
data = model.baseModel.getters('find')(id);
83498350
args = args || {};
8350-
args[model.singularName] = this.queryBuilder.transformOutgoingData(data);
8351+
args[model.singularName] = this.queryBuilder.transformOutgoingData(model, data);
83518352
mutationName = "create" + upcaseFirstLetter(model.singularName);
83528353
return [4 /*yield*/, this.mutate(mutationName, args, dispatch, model, false)];
83538354
case 1:
@@ -8391,7 +8392,8 @@ var VuexORMApollo = /** @class */ (function () {
83918392
Object.keys(args).forEach(function (key) {
83928393
var value = args[key];
83938394
if (value instanceof _this.context.components.Model) {
8394-
var transformedValue = _this.queryBuilder.transformOutgoingData(value);
8395+
var model_1 = _this.context.getModel(inflection$3.singularize(value.$self().entity));
8396+
var transformedValue = _this.queryBuilder.transformOutgoingData(model_1, value);
83958397
_this.context.logger.log('A', key, 'model was found within the variables and will be transformed from', value, 'to', transformedValue);
83968398
args[key] = transformedValue;
83978399
}
@@ -8420,7 +8422,7 @@ var VuexORMApollo = /** @class */ (function () {
84208422
model = this.context.getModel(state.$name);
84218423
args = args || {};
84228424
args['id'] = data.id;
8423-
args[model.singularName] = this.queryBuilder.transformOutgoingData(data);
8425+
args[model.singularName] = this.queryBuilder.transformOutgoingData(model, data);
84248426
mutationName = "update" + upcaseFirstLetter(model.singularName);
84258427
return [4 /*yield*/, this.mutate(mutationName, args, dispatch, model, false)];
84268428
case 1:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@types/graphql": "^0.12.3",
4545
"@types/inflection": "^1.5.28",
4646
"@types/lodash-es": "^4.17.0",
47-
"@vuex-orm/core": "^0.23.4",
47+
"@vuex-orm/core": "^0.24.4",
4848
"apollo-cache-inmemory": "^1.1.7",
4949
"apollo-client": "^2.2.2",
5050
"apollo-link": "^1.2.0",
@@ -82,7 +82,8 @@
8282
"typescript": "^2.7.1",
8383
"uglify-js": "^3.3.9",
8484
"webpack": "^3.10.0",
85-
"webpack-node-externals": "^1.6.0"
85+
"webpack-node-externals": "^1.6.0",
86+
"vuex": "^3.0.1"
8687
},
8788
"nyc": {
8889
"include": [

src/queryBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ export default class QueryBuilder {
128128
*
129129
* Omits relations and id fields.
130130
*
131+
* @param model
131132
* @param {Data} data
132133
* @returns {Data}
133134
*/
134-
public transformOutgoingData (data: Data): Data {
135-
const model: Model = this.getModel(data.$self().entity);
135+
public transformOutgoingData (model: Model, data: Data): Data {
136136
const relations: Map<string, Field> = model.getRelations();
137137
const returnValue: Data = {};
138138

src/vuex-orm-apollo.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { upcaseFirstLetter } from './utils';
88
import Context from './context';
99
import { Components } from '@vuex-orm/core/lib/plugins/use';
1010

11+
const inflection = require('inflection');
12+
1113
/**
1214
* Plugin class
1315
*/
@@ -113,7 +115,7 @@ export default class VuexORMApollo {
113115
const data = model.baseModel.getters('find')(id);
114116

115117
args = args || {};
116-
args[model.singularName] = this.queryBuilder.transformOutgoingData(data);
118+
args[model.singularName] = this.queryBuilder.transformOutgoingData(model, data);
117119

118120
const mutationName = `create${upcaseFirstLetter(model.singularName)}`;
119121
await this.mutate(mutationName, args, dispatch, model, false);
@@ -151,7 +153,8 @@ export default class VuexORMApollo {
151153
const value: any = args[key];
152154

153155
if (value instanceof this.context.components.Model) {
154-
const transformedValue = this.queryBuilder.transformOutgoingData(value);
156+
const model = this.context.getModel(inflection.singularize(value.$self().entity));
157+
const transformedValue = this.queryBuilder.transformOutgoingData(model, value);
155158
this.context.logger.log('A', key, 'model was found within the variables and will be transformed from', value, 'to', transformedValue);
156159
args[key] = transformedValue;
157160
}
@@ -175,7 +178,7 @@ export default class VuexORMApollo {
175178

176179
args = args || {};
177180
args['id'] = data.id;
178-
args[model.singularName] = this.queryBuilder.transformOutgoingData(data);
181+
args[model.singularName] = this.queryBuilder.transformOutgoingData(model, data);
179182

180183
const mutationName = `update${upcaseFirstLetter(model.singularName)}`;
181184
await this.mutate(mutationName, args, dispatch, model, false);

test/integration/VuexORMApollo.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,17 @@ mutation SignupUser($user: UserInput!, $captchaToken: String!) {
377377

378378
describe('$isPersisted', () => {
379379
it('is false for newly created records', async () => {
380-
let user = await store.dispatch('entities/users/insert', { data: { name: 'Snoopy' }} );
380+
const insertedData = await store.dispatch('entities/users/insert', { data: { name: 'Snoopy' }} );
381+
let user = insertedData.users[0];
381382
expect(user.$isPersisted).toBeFalsy();
382383

383384
user = store.getters['entities/users/find'](user.id);
384385
expect(user.$isPersisted).toBeFalsy();
385386
});
386387

387388
it('is true for persisted records', async () => {
388-
let user = await store.dispatch('entities/users/insert', { data: { name: 'Snoopy' }} );
389+
const insertedData = await store.dispatch('entities/users/insert', { data: { name: 'Snoopy' }} );
390+
let user = insertedData.users[0];
389391
const response = {
390392
data: {
391393
createUser: {

test/unit/QueryBuilder.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ describe('QueryBuilder', () => {
165165

166166
describe('.transformOutgoingData', () => {
167167
it('transforms models to a useful data hashmap', () => {
168-
const user = store.getters['entities/users/find']();
169-
const transformedData = queryBuilder.transformOutgoingData(user);
168+
const user = store.getters['entities/users/query']().first();
169+
const transformedData = queryBuilder.transformOutgoingData(vuexOrmApollo.context.getModel('user'), user);
170170
expect(transformedData).toEqual({ name: 'Charlie Brown' });
171171
});
172172
});

yarn.lock

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,9 @@
4848
version "0.5.3"
4949
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.5.3.tgz#91b728599544efbb7386d8b6633693a3c2e7ade5"
5050

51-
"@vuex-orm/core@^0.23.4":
52-
version "0.23.4"
53-
resolved "https://registry.yarnpkg.com/@vuex-orm/core/-/core-0.23.4.tgz#2cea71f46fb60868b769e4cc4e413d204ef2e9d2"
54-
dependencies:
55-
"@types/lodash-es" "^4.17.0"
56-
lodash-es "^4.17.7"
57-
normalizr "^3.2.4"
58-
vue "^2.5.16"
59-
vuex "^3.0.1"
51+
"@vuex-orm/core@^0.24.4":
52+
version "0.24.4"
53+
resolved "https://registry.yarnpkg.com/@vuex-orm/core/-/core-0.24.4.tgz#5f29f2fb1a9351e7eff2019b8348b5bc47d258e1"
6054

6155
abbrev@1:
6256
version "1.1.1"
@@ -2636,7 +2630,7 @@ locate-path@^2.0.0:
26362630
p-locate "^2.0.0"
26372631
path-exists "^3.0.0"
26382632

2639-
lodash-es@^4.17.5, lodash-es@^4.17.7:
2633+
lodash-es@^4.17.5:
26402634
version "4.17.7"
26412635
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.7.tgz#db240a3252c3dd8360201ac9feef91ac977ea856"
26422636

@@ -4302,7 +4296,7 @@ vue-parser@^1.1.5:
43024296
dependencies:
43034297
parse5 "^3.0.3"
43044298

4305-
vue@^2.5.13, vue@^2.5.16:
4299+
vue@^2.5.13:
43064300
version "2.5.16"
43074301
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.16.tgz#07edb75e8412aaeed871ebafa99f4672584a0085"
43084302

0 commit comments

Comments
 (0)