Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
phortx committed Jul 6, 2018
1 parent 1ccdfd7 commit 33f6c4d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions dist/vuex-orm-graphql.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27810,12 +27810,13 @@ var Schema = /** @class */ (function () {
return 'plain';
}
};
Schema.prototype.getType = function (name) {
Schema.prototype.getType = function (name, allowNull) {
if (allowNull === void 0) { allowNull = false; }
name = upcaseFirstLetter(name);
var type = this.types.get(name);
if (!type)
if (!allowNull && !type)
throw new Error("Couldn't find Type of name " + name + " in the GraphQL Schema.");
return type;
return type || null;
};
Schema.prototype.getMutation = function (name, allowNull) {
if (allowNull === void 0) { allowNull = false; }
Expand Down Expand Up @@ -28179,7 +28180,7 @@ var QueryBuilder = /** @class */ (function () {
var skipFieldDueId = (key === 'id' || isForeignKey) && !allowIdFields;
var schema = Context.getInstance().schema;
var type = schema.getType(model.singularName + (filter ? 'Filter' : ''));
var schemaField = (filter ? type.inputFields : type.fields).find(function (f) { return f.name === key; });
var schemaField = type ? (filter ? type.inputFields : type.fields).find(function (f) { return f.name === key; }) : null;
var isConnectionField = schemaField && Schema.getTypeNameOfField(schemaField).endsWith('TypeConnection');
// Ignore null fields, ids and connections
if (value && !skipFieldDueId && !isConnectionField) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class Context {
let type: GraphQLType;

try {
type = this.schema!.getType(model.singularName);
type = this.schema!.getType(model.singularName)!;
} catch (error) {
this.logger.warn(`Ignoring entity ${model.singularName} because it's not in the schema.`);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default class QueryBuilder {

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

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

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

if (schemaField && Schema.getTypeNameOfField(schemaField)) {
return Schema.getTypeNameOfField(schemaField);
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class Schema {

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

this.getType('Query').fields!.forEach(f => this.queries.set(f.name, f));
this.getType('Mutation').fields!.forEach(f => this.mutations.set(f.name, f));
this.getType('Query')!.fields!.forEach(f => this.queries.set(f.name, f));
this.getType('Mutation')!.fields!.forEach(f => this.mutations.set(f.name, f));
}

public determineQueryMode (): string {
Expand Down Expand Up @@ -44,13 +44,13 @@ export default class Schema {
}
}

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

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

return type;
return type || null;
}

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

0 comments on commit 33f6c4d

Please sign in to comment.