diff --git a/spec/schema/ast-validation-modules/ttl.spec.ts b/spec/schema/ast-validation-modules/ttl.spec.ts index f2309420..54cf69b3 100644 --- a/spec/schema/ast-validation-modules/ttl.spec.ts +++ b/spec/schema/ast-validation-modules/ttl.spec.ts @@ -2,8 +2,10 @@ import { assertValidatorAcceptsAndDoesNotWarn, assertValidatorRejects, assertValidatorWarns, + validate, } from './helpers'; import gql from 'graphql-tag'; +import { expect } from 'chai'; describe('timeToLive config', () => { it('accepts simple case', () => { @@ -445,4 +447,28 @@ describe('timeToLive config', () => { }, ); }); + + it('does not throw if cascadeFields are referencing relations that are non-object types', () => { + // previously, we had a bug where this threw instead of reporting an error + // it can quickly happen if there is a syntax error in the file that defines the relation type + assertValidatorRejects( + gql` + type Test @rootEntity { + finishedAt: DateTime + nested: String @relation + } + `, + 'Type "String" cannot be used with @relation because it is not a root entity type.', + { + timeToLive: [ + { + typeName: 'Test', + dateField: 'finishedAt', + expireAfterDays: 3, + cascadeFields: ['nested'], + }, + ], + }, + ); + }); }); diff --git a/src/model/implementation/time-to-live.ts b/src/model/implementation/time-to-live.ts index f4205885..ac4b1ebc 100644 --- a/src/model/implementation/time-to-live.ts +++ b/src/model/implementation/time-to-live.ts @@ -133,7 +133,9 @@ export class TimeToLiveType implements ModelComponent { // only allow cascade on forward relations. See Field#validateRelation() for details. if (!field.type.isObjectType) { - throw new Error(`Expected ${field.type.name} to be an object type`); + // isRelation = true if the type is not an object type is already an error, so we + // don't need to report an additional error + return; } const inverseField = field.type.fields.find((f) => f.inverseOf === field); if (!inverseField) {