From a59a7b2625569359747a740b9af04e9278e0df7a Mon Sep 17 00:00:00 2001 From: ypc-faros <99700024+ypc-faros@users.noreply.github.com> Date: Mon, 15 May 2023 09:54:00 -0400 Subject: [PATCH] Do not throw on unknown model (#140) --- src/schema.ts | 3 ++- test/schema.test.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/schema.ts b/src/schema.ts index 8a212de..fb881a1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -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, model: string): any { if (!isPlainObject(record)) { @@ -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); diff --git a/test/schema.test.ts b/test/schema.test.ts index 397f11c..97f86a5 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -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); + }); });