Skip to content

Commit

Permalink
Reject deprecated fields when interface field is not deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Nov 9, 2023
1 parent 2e29180 commit 1100177
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/type/__tests__/validation-test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 1100177

Please sign in to comment.