Skip to content

Commit 1100177

Browse files
committed
Reject deprecated fields when interface field is not deprecated
1 parent 2e29180 commit 1100177

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/type/__tests__/validation-test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,33 @@ describe('Interfaces must adhere to Interface they implement', () => {
27342734
},
27352735
]);
27362736
});
2737+
2738+
it('rejects deprecated implementation field when interface field is not deprecated', () => {
2739+
const schema = buildSchema(`
2740+
interface Node {
2741+
id: ID!
2742+
}
2743+
2744+
type Foo implements Node {
2745+
id: ID! @deprecated
2746+
}
2747+
2748+
type Query {
2749+
foo: Foo
2750+
}
2751+
`);
2752+
2753+
expectJSON(validateSchema(schema)).toDeepEqual([
2754+
{
2755+
message:
2756+
'Interface field Node.id is not deprecated, so implementation field Foo.id must not be deprecated.',
2757+
locations: [
2758+
{ line: 7, column: 17 },
2759+
{ line: 7, column: 13 },
2760+
],
2761+
},
2762+
]);
2763+
});
27372764
});
27382765

27392766
describe('assertValidSchema', () => {

src/type/validate.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ function validateTypeImplementsInterface(
433433
);
434434
}
435435
}
436+
437+
// Asserts that field is not deprecated unless interface field is
438+
if (
439+
ifaceField.deprecationReason == null &&
440+
typeField.deprecationReason != null
441+
) {
442+
context.reportError(
443+
`Interface field ${iface.name}.${fieldName} is not deprecated, so ` +
444+
`implementation field ${type.name}.${fieldName} must not be deprecated.`,
445+
[
446+
getDeprecatedDirectiveNode(typeField.astNode),
447+
typeField.astNode?.type,
448+
],
449+
);
450+
}
436451
}
437452
}
438453

0 commit comments

Comments
 (0)