GraphQL @deprecated Directive vs Apollo Server Introspection: Compatibility Across Versions
0 reputation · 15 Jun 2020, 09:42 UTC
0 reputation · 15 Jun 2020, 09:42 UTC
We need to verify that Apollo Server correctly reports @deprecated fields during introspection, especially across recent releases. The GraphQL specification mandates that a deprecated field must expose isDeprecated: true and a deprecationReason string via the __type introspection system. Historically, Apollo Server 2.x adhered to this contract, but a regression was observed in the 3.0.0‑beta series where isDeprecated was incorrectly reported as false for SDL‑defined deprecated fields. Subsequent patches addressed the issue, yet the exact behavior in 3.x and later remains unclear, particularly when using SDL‑first versus code‑first schema definitions.
@deprecated(reason: "use newField") return isDeprecated: true?deprecationReason match the supplied reason string in these versions?35275 reputation · 15 Jun 2020, 21:12 UTC
In Apollo Server 3.1.0 and newer, introspection queries correctly report @deprecated fields according to the GraphQL specification. A field annotated with @deprecated(reason: "use newField") will return isDeprecated: true and the matching deprecationReason string in the introspection result.
The regression observed in the 3.0.0-beta series was addressed in subsequent patches. In current stable versions of 3.x and 4.x, the behavior is consistent regardless of how the schema is constructed:
makeExecutableSchema with string templates, the parser correctly maps the @deprecated directive to the __type introspection-fields.GraphQLObjectType), setting the deprecated and deprecationReason properties on the field definition yields the same introspection output.To verify this in your specific environment, execute the following introspection query against your Apollo Server instance:
query CheckDeprecation {
__type(name: "YourTypeName") {
fields {
name
isDeprecated
deprecationReason
}
}
}
If isDeprecated returns false despite the directive being in your code, check for the following:
@deprecated name, which could prevent the default parser from processing the metadata.To provide a more specific diagnosis, please confirm if you are using schema stitching, federation, or a monolithic schema defined via makeExecutableSchema.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.