Skip to content
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

Reject deprecated fields when interface field is not deprecated #3986

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/type/__tests__/validation-test.ts
Expand Up @@ -2734,6 +2734,33 @@ describe('Interfaces must adhere to Interface they implement', () => {
},
]);
});

it('rejects deprecated implementation field when interface field is not deprecated', () => {
const schema = buildSchema(`
interface Node {
id: ID!
}

type Foo implements Node {
id: ID! @deprecated
}

type Query {
foo: Foo
}
`);

expectJSON(validateSchema(schema)).toDeepEqual([
{
message:
'Interface field Node.id is not deprecated, so implementation field Foo.id must not be deprecated.',
locations: [
{ line: 7, column: 17 },
{ line: 7, column: 13 },
],
},
]);
});
});

describe('assertValidSchema', () => {
Expand Down
15 changes: 15 additions & 0 deletions src/type/validate.ts
Expand Up @@ -433,6 +433,21 @@ function validateTypeImplementsInterface(
);
}
}

// Asserts that field is not deprecated unless interface field is
if (
ifaceField.deprecationReason == null &&
typeField.deprecationReason != null
) {
context.reportError(
`Interface field ${iface.name}.${fieldName} is not deprecated, so ` +
`implementation field ${type.name}.${fieldName} must not be deprecated.`,
[
getDeprecatedDirectiveNode(typeField.astNode),
typeField.astNode?.type,
],
);
}
}
}

Expand Down