apollographql / apollographql/federation
[Federation] Handle directives at the gateway level, or in other services
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Is there a way to handle directives at the gateway level? If not, is it possible to handle directives in one service and use them in others?
Let's say we have a Dog service as a participant on the federation which uses a custom directive on some fields. The directive is defined in Dog's schema, but no `schemaDirective` class is defined to handle what the directive does.
Is it possible to define a schemaDirective in a different place? Ideally at the gateway level or in some other global place, but given that gateways understandably cannot have actual schemas (even though this isn't a schema, it's a directive) maybe in another service instead? For example if service Cat defines the same directive in its schema but also provides a schemaDirective definition to handle the directive, is there a way I can make Dog's directives get resolved by the same handlers?
In case it helps my specific use case is that I want services to be able to annotate certain things and then have the gateway make authorization checks based on these annotations before it even calls out to the individual services to run their resolvers. This would let us have gateway-level authorization instead of implementing authorization handling on each individual service.
If you think this workflow is flawed or something, feel free to offer feedback. My current workaround is going to be to just suck it up and implement this directive handler in each service (which I'll abstract into a package of its own). And each service will make requests to our authorization service directly. I would (perhaps naively?) prefer if the gateway would handle authorizing requests with the authorization service before it even calls out to individual services, but I do not think this is possible with the current apollo server API.
Contributor guide
Research direction
Start by reviewing the Apollo Server API, federation gateway behavior, and the schemaDirective handling described in the issue. Determine whether directives can be resolved across services or at the gateway, and define a supported authorization workflow before proposing implementation work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, authorization, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100