diff --git a/packages/graphql/src/schema/make-augmented-schema.test.ts b/packages/graphql/src/schema/make-augmented-schema.test.ts index 712c6e9e70..6631c968b5 100644 --- a/packages/graphql/src/schema/make-augmented-schema.test.ts +++ b/packages/graphql/src/schema/make-augmented-schema.test.ts @@ -209,7 +209,7 @@ describe("makeAugmentedSchema", () => { }); }); - test("should throw error if auth is used on relationship properties interface", () => { + test("should throw error if @auth is used on relationship properties interface", () => { const typeDefs = ` type Movie { actors: Actor @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") @@ -229,7 +229,7 @@ describe("makeAugmentedSchema", () => { ); }); - test("should throw error if auth is used on relationship property", () => { + test("should throw error if @auth is used on relationship property", () => { const typeDefs = ` type Movie { actors: Actor @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") @@ -246,4 +246,24 @@ describe("makeAugmentedSchema", () => { expect(() => makeAugmentedSchema({ typeDefs })).toThrow("Cannot have @auth directive on relationship property"); }); + + test("should throw error if @relationship is used on relationship property", () => { + const typeDefs = ` + type Movie { + actors: Actor @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") + } + + type Actor { + name: String + } + + interface ActedIn { + actors: Actor @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") + } + `; + + expect(() => makeAugmentedSchema({ typeDefs })).toThrow( + "Cannot have @relationship directive on relationship property" + ); + }); }); diff --git a/packages/graphql/src/schema/make-augmented-schema.ts b/packages/graphql/src/schema/make-augmented-schema.ts index 0f4c294362..bb0eb10b90 100644 --- a/packages/graphql/src/schema/make-augmented-schema.ts +++ b/packages/graphql/src/schema/make-augmented-schema.ts @@ -277,10 +277,13 @@ function makeAugmentedSchema( const fields = {}; relationship.fields?.forEach((field) => { - const authDirective = (field.directives || []).find((x) => x.name.value === "auth"); - if (authDirective) { - throw new Error("Cannot have @auth directive on relationship property"); - } + const forbiddenDirectives = ["auth", "relationship"]; + forbiddenDirectives.forEach((directive) => { + const found = (field.directives || []).find((x) => x.name.value === directive); + if (found) { + throw new Error(`Cannot have @${directive} directive on relationship property`); + } + }); const typeMeta = getFieldTypeMeta(field);