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); + }); });