apollographql / apollographql/federation
Gateway itself does not have service definition (use case: gateway in another gateway)
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Hi,
I'm trying to make a service which adds some operations to another pre-existing graph, which is itself already made of federated services. For short, here is the big picture:
```
S1 -\
>-> G1 -------\
S2 -/ | >-> G2
\-> S3 -/
```
I'm fine discussing why on earth I'd make such silly thing, but I believe this solves my problem effectively. G1 is a publicly available service, and must be kept so. S3 is actually a client of G1, and define new queries and mutations which rely on S1 and/or S2 under the hood. It uses types defined by G1, e.g. it adds a new query which returns an entity defined in S1, and it would work thanks to G2.
During prior development, G2 did not rely on G1 but directly on S1 and S2 (and always S3) and it worked fine. However, the doc states that federated services should not be publicly reachable, among others because the authentication can be handled by the gateway so that services would not take care of that. Well the point is G2 shouldn't be able to reach S1 nor S2 anymore, but should talk to G1 directly.
And it nearly works! But there's a problem: G1 does not advertise the full union of S1 and S2, but only one of them. G1 starts fine, it queries the service definition of S1 and S2 and builds the resulting schema. The schema should be valid, because G1 works fine, and introspecting the gateway seems fine too (`const { schema } = await gateway.load()`).
Thereafter, if G2 starts, it queries the service definition of G1 and S3. However G1 responds with only the schema definition of one of S1 or S2, which is sadly wrong! It seems it always returns the same schema definition, whatever the order of `serviceList` is, I guess this has to do with the order entities are resolved.
I expect that a gateway declares a service definition which is the union of its federated services' ones.
I've seen no tests which check the gateway's server response to that query.
For reference, that query is `__ApolloGetServiceDefinition__ { _service { sdl } }`
Tested with
@apollo/gateway: 0.14.1, 0.19.1
apollo-server: 2.12.0, 2.16.1
Contributor guide
Research direction
Start by reproducing the nested gateway setup with G1, G2, S1, S2, and S3, then run __ApolloGetServiceDefinition__ against G1 and compare its SDL with gateway.load().done means the gateway response advertises the union of its federated service definitions, with a test covering the server response.
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
- Mostly clear
- Newbie friendliness
- 35/100