Skip to content

Commit

Permalink
Do not throw on unknown model (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypc-faros committed May 15, 2023
1 parent 9627893 commit a59a7b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class FarosGraphSchema {
* Given a JSON record and a Faros model, convert the necessary date fields in
* the record to: Javascript dates (Timestamp fields) or ISO formatted string
* (timestamptz fields)
* Records for models unknown to the schema are returned unchanged
*/
fixTimestampFields(record: Dictionary<any>, model: string): any {
if (!isPlainObject(record)) {
Expand All @@ -54,7 +55,7 @@ export class FarosGraphSchema {

const node = this.objectTypeDefs[model];
if (!node) {
throw new VError('Model type %s was not found in the schema', model);
return record;
}

const fieldTypes = keyBy(node.fields, (n) => n.name.value);
Expand Down
5 changes: 5 additions & 0 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,9 @@ describe('schema', () => {
.createdAt
).toEqual(new Date(123));
});

test('leaves unknown model record untouched', () => {
const record = {uid: 'abc'};
expect(schema.fixTimestampFields(record, 'unknown_Model')).toEqual(record);
});
});

0 comments on commit a59a7b2

Please sign in to comment.