Authentication through directives
Authentication through directives — GraphQL Mesh documentation.
You can use the @authenticated, @requiresScope, @policy and @skipAuth directives to control
access to your GraphQL API. These directives are used to enforce authentication and authorization
rules on your supergraph.
Granular field access by Federation auth directives (@authenticated, @requiresScopes, @policy)
You can use the authenticated directive to enforce authentication rules on specific fields. This
directive can be used to restrict access to certain fields based on the viewer’s session.
Then, you can use the authenticated directive to set authentication rules on fields:
Since @authenticated is a native directive, you can import it instead of defining it explicitly;
Exclude fields from authentication by using schema field directive @skipAuth
If you have completely protected supergraph but allow unauthenticated access for certain fields by annotating them.
You need to define the skipAuth directive in your schema:
Then, you can use the skipAuth directive to exclude fields from authentication: