apollographql / apollographql/federation
How to dynamically route request to service list
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Is it possible to route request dynamically by request host?
For example, if request host if **us-dev.mycompany.org**, i would like to route this request to **graph-mdm.us-dev** in service list.
`
class DnsRouteDataSource extends RemoteGraphQLDataSource {
willSendRequest({request, context}) {
if (request.host === 'us-dev.mycompany.org') {
//send request to graph-mdm.us-dev
} else if (request.host === 'graph-mdm.uk-dev') {
//send request to graph-mdm.uk-dev
}
}
}
const gateway = new ApolloGateway({
serviceList: [
{name: 'graph-mdm.us-dev', url: 'http://10.17.80.125:8080'},
{name: 'graph-mdm.uk-dev', url: 'http://10.17.80.126:8080'},
],
buildService({name, url}) {
return new DnsRouteDataSource({url});
}
});
`
Contributor guide
Research direction
Start with the DnsRouteDataSource.willSendRequest example and the ApolloGateway serviceList/buildService entry points shown in the issue. Determine whether routing can be selected from the request host, and define how the two listed services should be resolved and validated before considering the behavior complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100