Skip to content

Commit 85066a0

Browse files
benjieJoviDeCroock
andauthoredMar 8, 2025··
Reject deprecated fields when interface field is not deprecated (#3986)
This PR implements GraphQL RFC graphql/graphql-spec#1053; please see that PR for details. --------- Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
 

‎src/type/__tests__/validation-test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,33 @@ describe('Interfaces must adhere to Interface they implement', () => {
33533353
},
33543354
]);
33553355
});
3356+
3357+
it('rejects deprecated implementation field when interface field is not deprecated', () => {
3358+
const schema = buildSchema(`
3359+
interface Node {
3360+
id: ID!
3361+
}
3362+
3363+
type Foo implements Node {
3364+
id: ID! @deprecated
3365+
}
3366+
3367+
type Query {
3368+
foo: Foo
3369+
}
3370+
`);
3371+
3372+
expectJSON(validateSchema(schema)).toDeepEqual([
3373+
{
3374+
message:
3375+
'Interface field Node.id is not deprecated, so implementation field Foo.id must not be deprecated.',
3376+
locations: [
3377+
{ line: 7, column: 17 },
3378+
{ line: 7, column: 13 },
3379+
],
3380+
},
3381+
]);
3382+
});
33563383
});
33573384

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

‎src/type/validate.ts

+15
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,21 @@ function validateTypeImplementsInterface(
573573
}
574574
}
575575
}
576+
577+
// Asserts that field is not deprecated unless interface field is
578+
if (
579+
typeField.deprecationReason != null &&
580+
ifaceField.deprecationReason == null
581+
) {
582+
context.reportError(
583+
`Interface field ${iface.name}.${ifaceField.name} is not deprecated, so ` +
584+
`implementation field ${type.name}.${typeField.name} must not be deprecated.`,
585+
[
586+
getDeprecatedDirectiveNode(typeField.astNode),
587+
typeField.astNode?.type,
588+
],
589+
);
590+
}
576591
}
577592
}
578593

0 commit comments

Comments
 (0)
Please sign in to comment.