Skip to content

Error relationship on relationship properties #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/graphql/src/schema/make-augmented-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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"
);
});
});
11 changes: 7 additions & 4 deletions packages/graphql/src/schema/make-augmented-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down