apollographql / apollographql/federation

ApolloServer + geteway disable initial request, or handle auth error

Open
#407 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

it appears that ApolloServer + ApolloGeteway will make an initial request to each endpoint.

in a scenario where we need to get authorization token from a user request, this initial call will fail.

in this case, the first call fails, and ApolloServer no longer sends any requests to that url.

would it be possible to either avoid the first request, or send it somewhere else (when auth token is not available) ? alternatively maybe we can handle the error so that future request still go out

```
const gateway = new ApolloGateway({
serviceList: [
{ name: 'svc1', url: svc1url }, {...}
],
buildService({ name, url }) {
return new AuthenticatedDataSource({ url });
},
});

const server = new ApolloServer({
gateway,
subscriptions: false,
context: (ctx:ExpressContext) => {
return {auth: ctx.req.header('authorization')}
}
});
```

Contributor guide

Open the contributing guide

Research direction

No file or test is named in the issue. Start with the ApolloGateway serviceList/buildService path and the AuthenticatedDataSource shown in the example; reproduce an initial request without an authorization header and determine the expected behavior for subsequent requests. Done means the chosen behavior is specified and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.