Skip to content

Commit a9e0a70

Browse files
committed
Bugfixes
1 parent 8218f52 commit a9e0a70

File tree

4 files changed

+32
-59
lines changed

4 files changed

+32
-59
lines changed

dist/vuex-orm-apollo.esm.js

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,6 @@ function isListValue(value) {
803803
function isEnumValue(value) {
804804
return value.kind === 'EnumValue';
805805
}
806-
function isNullValue(value) {
807-
return value.kind === 'NullValue';
808-
}
809806
function valueToObjectRepresentation(argObj, name, value, variables) {
810807
if (isIntValue(value) || isFloatValue(value)) {
811808
argObj[name.value] = Number(value.value);
@@ -834,9 +831,6 @@ function valueToObjectRepresentation(argObj, name, value, variables) {
834831
else if (isEnumValue(value)) {
835832
argObj[name.value] = value.value;
836833
}
837-
else if (isNullValue(value)) {
838-
argObj[name.value] = null;
839-
}
840834
else {
841835
throw new Error("The inline argument \"" + name.value + "\" of kind \"" + value.kind + "\" is not supported.\n Use variables instead of inline arguments to overcome this limitation.");
842836
}
@@ -865,14 +859,6 @@ function storeKeyNameFromField(field, variables) {
865859
}
866860
return getStoreKeyName(field.name.value, argObj, directivesObj);
867861
}
868-
var KNOWN_DIRECTIVES = [
869-
'connection',
870-
'include',
871-
'skip',
872-
'client',
873-
'rest',
874-
'export',
875-
];
876862
function getStoreKeyName(fieldName, args, directives) {
877863
if (directives &&
878864
directives['connection'] &&
@@ -894,24 +880,11 @@ function getStoreKeyName(fieldName, args, directives) {
894880
return directives['connection']['key'];
895881
}
896882
}
897-
var completeFieldName = fieldName;
898883
if (args) {
899884
var stringifiedArgs = JSON.stringify(args);
900-
completeFieldName += "(" + stringifiedArgs + ")";
885+
return fieldName + "(" + stringifiedArgs + ")";
901886
}
902-
if (directives) {
903-
Object.keys(directives).forEach(function (key) {
904-
if (KNOWN_DIRECTIVES.indexOf(key) !== -1)
905-
return;
906-
if (directives[key] && Object.keys(directives[key]).length) {
907-
completeFieldName += "@" + key + "(" + JSON.stringify(directives[key]) + ")";
908-
}
909-
else {
910-
completeFieldName += "@" + key;
911-
}
912-
});
913-
}
914-
return completeFieldName;
887+
return fieldName;
915888
}
916889
function argumentsObjectFromField(field, variables) {
917890
if (field.arguments && field.arguments.length) {
@@ -983,7 +956,7 @@ function shouldInclude(selection, variables) {
983956
var evaledValue = false;
984957
if (!ifValue || ifValue.kind !== 'BooleanValue') {
985958
if (ifValue.kind !== 'Variable') {
986-
throw new Error("Argument for the @" + directiveName + " directive must be a variable or a boolean value.");
959+
throw new Error("Argument for the @" + directiveName + " directive must be a variable or a bool ean value.");
987960
}
988961
else {
989962
evaledValue = variables[ifValue.name.value];
@@ -1230,24 +1203,6 @@ var TYPENAME_FIELD = {
12301203
value: '__typename',
12311204
},
12321205
};
1233-
function isNotEmpty(op, fragments) {
1234-
return (op.selectionSet.selections.filter(function (selectionSet) {
1235-
return !(selectionSet &&
1236-
selectionSet.kind === 'FragmentSpread' &&
1237-
!isNotEmpty(fragments[selectionSet.name.value], fragments));
1238-
}).length > 0);
1239-
}
1240-
function getDirectiveMatcher(directives) {
1241-
return function directiveMatcher(directive) {
1242-
return directives.some(function (dir) {
1243-
if (dir.name && dir.name === directive.name.value)
1244-
return true;
1245-
if (dir.test && dir.test(directive))
1246-
return true;
1247-
return false;
1248-
});
1249-
};
1250-
}
12511206
function addTypenameToSelectionSet(selectionSet, isRoot) {
12521207
if (isRoot === void 0) { isRoot = false; }
12531208
if (selectionSet.selections) {
@@ -1285,10 +1240,15 @@ function removeDirectivesFromSelectionSet(directives, selectionSet) {
12851240
!selection ||
12861241
!selection.directives)
12871242
return selection;
1288-
var directiveMatcher = getDirectiveMatcher(directives);
12891243
var remove;
12901244
selection.directives = selection.directives.filter(function (directive) {
1291-
var shouldKeep = !directiveMatcher(directive);
1245+
var shouldKeep = !directives.some(function (dir) {
1246+
if (dir.name && dir.name === directive.name.value)
1247+
return true;
1248+
if (dir.test && dir.test(directive))
1249+
return true;
1250+
return false;
1251+
});
12921252
if (!remove && !shouldKeep && agressiveRemove)
12931253
remove = true;
12941254
return shouldKeep;
@@ -1311,7 +1271,14 @@ function removeDirectivesFromDocument(directives, doc) {
13111271
});
13121272
var operation = getOperationDefinitionOrDie(docClone);
13131273
var fragments = createFragmentMap(getFragmentDefinitions(docClone));
1314-
return isNotEmpty(operation, fragments) ? docClone : null;
1274+
var isNotEmpty = function (op) {
1275+
return op.selectionSet.selections.filter(function (selectionSet) {
1276+
return !(selectionSet &&
1277+
selectionSet.kind === 'FragmentSpread' &&
1278+
!isNotEmpty(fragments[selectionSet.name.value]));
1279+
}).length > 0;
1280+
};
1281+
return isNotEmpty(operation) ? docClone : null;
13151282
}
13161283
var added$1 = new Map();
13171284
function addTypenameToDocument(doc) {
@@ -7896,8 +7863,8 @@ var QueryBuilder = /** @class */ (function () {
78967863
if (args) {
78977864
Object.keys(args).forEach(function (key) {
78987865
var value = args[key];
7899-
// Ignore ids and connections
7900-
if (!(value instanceof Array || (key === 'id' && !allowIdFields))) {
7866+
// Ignore null fields, ids and connections
7867+
if (value && !(value instanceof Array || (key === 'id' && !allowIdFields))) {
79017868
var typeOrValue = '';
79027869
if (signature) {
79037870
if (typeof value === 'object' && value.__type) {
@@ -7939,10 +7906,11 @@ var QueryBuilder = /** @class */ (function () {
79397906
return '';
79407907
var relationQueries = [];
79417908
model.getRelations().forEach(function (field, name) {
7942-
var relatedModel = _this.getModel(name);
7909+
var relatedModel = _this.getModel(field.related ? field.related.name : name);
79437910
if (_this.shouldEagerLoadRelation(model, field, relatedModel) &&
79447911
!_this.shouldModelBeIgnored(relatedModel, ignoreModels)) {
7945-
var multiple = !(field instanceof _this.context.components.BelongsTo);
7912+
var multiple = !(field instanceof _this.context.components.BelongsTo ||
7913+
field instanceof _this.context.components.HasOne);
79467914
relationQueries.push(_this.buildField(relatedModel, multiple, undefined, ignoreModels));
79477915
}
79487916
});
@@ -8102,7 +8070,7 @@ var Context = /** @class */ (function () {
81028070
*/
81038071
Context.prototype.getModel = function (model) {
81048072
if (typeof model === 'string') {
8105-
var name_1 = inflection$2.singularize(model);
8073+
var name_1 = inflection$2.singularize(downcaseFirstLetter(model));
81068074
model = this.models.get(name_1);
81078075
if (!model)
81088076
throw new Error("No such model " + name_1 + "!");

src/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Logger from './logger';
22
import Model from './model';
33
import { ORMModel } from './interfaces';
44
import { Components, Options } from '@vuex-orm/core/lib/plugins/use';
5+
import { downcaseFirstLetter } from './utils';
56
const inflection = require('inflection');
67

78
export default class Context {
@@ -35,7 +36,7 @@ export default class Context {
3536
*/
3637
public getModel (model: Model | string): Model {
3738
if (typeof model === 'string') {
38-
const name: string = inflection.singularize(model);
39+
const name: string = inflection.singularize(downcaseFirstLetter(model));
3940
model = this.models.get(name) as Model;
4041
if (!model) throw new Error(`No such model ${name}!`);
4142
}

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface Arguments extends Object {
2828
}
2929

3030
export interface ORMModel {
31+
name: string;
3132
entity: string;
3233
eagerLoad: undefined | Array<string>;
3334

src/queryBuilder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,14 @@ export default class QueryBuilder {
270270
const relationQueries: Array<string> = [];
271271

272272
model.getRelations().forEach((field: Field, name: string) => {
273-
const relatedModel: Model = this.getModel(name);
273+
const relatedModel: Model = this.getModel(field.related ? field.related.name : name);
274274

275275
if (this.shouldEagerLoadRelation(model, field, relatedModel) &&
276276
!this.shouldModelBeIgnored(relatedModel, ignoreModels)) {
277-
const multiple: boolean = !(field instanceof this.context.components.BelongsTo);
277+
278+
const multiple: boolean = !(field instanceof this.context.components.BelongsTo ||
279+
field instanceof this.context.components.HasOne);
280+
278281
relationQueries.push(this.buildField(relatedModel, multiple, undefined, ignoreModels));
279282
}
280283
});

0 commit comments

Comments
 (0)