File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
spec/schema/ast-validation-modules Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ import {
22 assertValidatorAcceptsAndDoesNotWarn ,
33 assertValidatorRejects ,
44 assertValidatorWarns ,
5+ validate ,
56} from './helpers' ;
67import gql from 'graphql-tag' ;
8+ import { expect } from 'chai' ;
79
810describe ( 'timeToLive config' , ( ) => {
911 it ( 'accepts simple case' , ( ) => {
@@ -445,4 +447,28 @@ describe('timeToLive config', () => {
445447 } ,
446448 ) ;
447449 } ) ;
450+
451+ it ( 'does not throw if cascadeFields are referencing relations that are non-object types' , ( ) => {
452+ // previously, we had a bug where this threw instead of reporting an error
453+ // it can quickly happen if there is a syntax error in the file that defines the relation type
454+ assertValidatorRejects (
455+ gql `
456+ type Test @rootEntity {
457+ finishedAt: DateTime
458+ nested: String @relation
459+ }
460+ ` ,
461+ 'Type "String" cannot be used with @relation because it is not a root entity type.' ,
462+ {
463+ timeToLive : [
464+ {
465+ typeName : 'Test' ,
466+ dateField : 'finishedAt' ,
467+ expireAfterDays : 3 ,
468+ cascadeFields : [ 'nested' ] ,
469+ } ,
470+ ] ,
471+ } ,
472+ ) ;
473+ } ) ;
448474} ) ;
Original file line number Diff line number Diff line change @@ -133,7 +133,9 @@ export class TimeToLiveType implements ModelComponent {
133133
134134 // only allow cascade on forward relations. See Field#validateRelation() for details.
135135 if ( ! field . type . isObjectType ) {
136- throw new Error ( `Expected ${ field . type . name } to be an object type` ) ;
136+ // isRelation = true if the type is not an object type is already an error, so we
137+ // don't need to report an additional error
138+ return ;
137139 }
138140 const inverseField = field . type . fields . find ( ( f ) => f . inverseOf === field ) ;
139141 if ( ! inverseField ) {
You can’t perform that action at this time.
0 commit comments