GraphQL schema accessibility metadata handling in Apollo Server 4 when using a custom @accessible directive
0 reputation · 08 Mar 2020, 22:01 UTC
0 reputation · 08 Mar 2020, 22:01 UTC
The goal is to determine whether a custom @accessible directive can be used to attach accessibility information (such as ARIA roles or labels) to GraphQL fields and have that information survive introspection and error‑payload generation in Apollo Server 4.
Because the GraphQL specification does not standardize accessibility metadata, servers may ignore unknown directives, and clients may not expose them through introspection. This creates uncertainty about whether the directive will be preserved in __schema, whether tooling like Apollo Studio will surface it, and whether error responses can be extended with accessibility‑focused properties without breaking generic clients.
What behavior does Apollo Server 4 exhibit when a schema includes the @accessible directive? Does the directive appear in introspection results, and can it be leveraged by clients to produce screen‑reader‑friendly UI or error messages?
34775 reputation · 09 Mar 2020, 00:08 UTC
In Apollo Server 4, a custom @accessible directive can be defined in your schema, but it cannot be used as a primary mechanism to pass accessibility metadata to clients via standard introspection. While the server recognizes the directive's existence, it does not expose the application of that directive to individual fields during introspection queries.
@accessible directive will appear in the __schema.directives list, confirming that the server knows the directive exists and understands its valid locations.directives field on __Field or __EnumValue. Consequently, a client querying for field metadata will not see which fields are marked with @accessible.Apollo Server 4 does not automatically inject directive metadata into error responses. The default error payload contains only message, locations, and path. To include accessibility-focused properties (like ARIA labels for a specific failing field) in an error, you must manually extend the GraphQLError extensions object within your resolver or plugin.
If your clients require accessibility metadata to render screen-reader-friendly UIs, consider these alternatives:
accessibilityMetadata field on your types that returns a dedicated AccessibilityInfo object.__schema or __type fields to inject directive data into the introspection response (though this may break compatibility with some standard clients).To verify this behavior in your environment, run the following introspection query:
{
__schema {
directives {
name
}
types {
name
fields {
name
# Note: There is no 'directives' field available here in standard GraphQL
}
}
}
}
You will observe that while @accessible appears in the directives list, it is absent from the fields metadata.
Diagnostic Detail Needed: Are you using a custom introspectionSchema or a specific Apollo plugin that modifies the default introspection resolvers?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.