Skip to content

Commit dd45aa5

Browse files
committed
Bugfix
1 parent 1243ef7 commit dd45aa5

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

dist/vuex-orm-graphql.esm.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27810,12 +27810,13 @@ var Schema = /** @class */ (function () {
2781027810
return 'plain';
2781127811
}
2781227812
};
27813-
Schema.prototype.getType = function (name) {
27813+
Schema.prototype.getType = function (name, allowNull) {
27814+
if (allowNull === void 0) { allowNull = false; }
2781427815
name = upcaseFirstLetter(name);
2781527816
var type = this.types.get(name);
27816-
if (!type)
27817+
if (!allowNull && !type)
2781727818
throw new Error("Couldn't find Type of name " + name + " in the GraphQL Schema.");
27818-
return type;
27819+
return type || null;
2781927820
};
2782027821
Schema.prototype.getMutation = function (name, allowNull) {
2782127822
if (allowNull === void 0) { allowNull = false; }
@@ -28179,7 +28180,7 @@ var QueryBuilder = /** @class */ (function () {
2817928180
var skipFieldDueId = (key === 'id' || isForeignKey) && !allowIdFields;
2818028181
var schema = Context.getInstance().schema;
2818128182
var type = schema.getType(model.singularName + (filter ? 'Filter' : ''));
28182-
var schemaField = (filter ? type.inputFields : type.fields).find(function (f) { return f.name === key; });
28183+
var schemaField = type ? (filter ? type.inputFields : type.fields).find(function (f) { return f.name === key; }) : null;
2818328184
var isConnectionField = schemaField && Schema.getTypeNameOfField(schemaField).endsWith('TypeConnection');
2818428185
// Ignore null fields, ids and connections
2818528186
if (value && !skipFieldDueId && !isConnectionField) {

src/common/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export default class Context {
237237
let type: GraphQLType;
238238

239239
try {
240-
type = this.schema!.getType(model.singularName);
240+
type = this.schema!.getType(model.singularName)!;
241241
} catch (error) {
242242
this.logger.warn(`Ignoring entity ${model.singularName} because it's not in the schema.`);
243243
return;

src/graphql/query-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default class QueryBuilder {
174174

175175
const schema = Context.getInstance().schema!;
176176
const type = schema.getType(model.singularName + (filter ? 'Filter' : ''));
177-
const schemaField = (filter ? type.inputFields! : type.fields!).find(f => f.name === key);
177+
const schemaField = type ? (filter ? type.inputFields! : type.fields!).find(f => f.name === key) : null;
178178
const isConnectionField = schemaField && Schema.getTypeNameOfField(schemaField).endsWith('TypeConnection');
179179

180180
// Ignore null fields, ids and connections
@@ -232,7 +232,7 @@ export default class QueryBuilder {
232232
const context: Context = Context.getInstance();
233233
const field: undefined | Field = model.fields.get(key);
234234

235-
const schemaField = context.schema!.getType(model.singularName).fields!.find(f => f.name === key);
235+
const schemaField = context.schema!.getType(model.singularName)!.fields!.find(f => f.name === key);
236236

237237
if (schemaField && Schema.getTypeNameOfField(schemaField)) {
238238
return Schema.getTypeNameOfField(schemaField);

src/graphql/schema.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class Schema {
1515

1616
this.schema.types.forEach((t: GraphQLType) => this.types.set(t.name, t));
1717

18-
this.getType('Query').fields!.forEach(f => this.queries.set(f.name, f));
19-
this.getType('Mutation').fields!.forEach(f => this.mutations.set(f.name, f));
18+
this.getType('Query')!.fields!.forEach(f => this.queries.set(f.name, f));
19+
this.getType('Mutation')!.fields!.forEach(f => this.mutations.set(f.name, f));
2020
}
2121

2222
public determineQueryMode (): string {
@@ -44,13 +44,13 @@ export default class Schema {
4444
}
4545
}
4646

47-
public getType (name: string): GraphQLType {
47+
public getType (name: string, allowNull: boolean = false): GraphQLType | null {
4848
name = upcaseFirstLetter(name);
4949
const type = this.types.get(name);
5050

51-
if (!type) throw new Error(`Couldn't find Type of name ${name} in the GraphQL Schema.`);
51+
if (!allowNull && !type) throw new Error(`Couldn't find Type of name ${name} in the GraphQL Schema.`);
5252

53-
return type;
53+
return type || null;
5454
}
5555

5656
public getMutation (name: string, allowNull: boolean = false): GraphQLField | null {

0 commit comments

Comments
 (0)