apollographql / apollographql/federation
@provides on field which is itself provided does not work
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Given three services A,B and C with following schemas:
`A`
```
type A @key(fields: "id") {
id: ID!
a: String!
}
type Query {
as: [A!]!
}
```
`B`
```
type A @key(fields: "id") @extends {
id: ID! @external
a: String! @external
}
type B @key(fields: "id") {
id: ID!
refA: A @provides(fields: "a")
b: String!
}
type Query {
bs: [B!]!
}
```
`C`
```
type A @key(fields: "id") @extends {
id: ID! @external
a: String! @external
}
type B @key(fields: "id") @extends {
id: ID! @external
refA: A @external
}
type C {
id: ID!
refB: B @provides(fields: "refA{ a }")
c: String!
}
type Query {
cs: [C!]!
}
```
I want to be able to post queries
```
query askB{
bs{
b
refA{ a }
}
}
```
and
```
query askC{
cs{
c
refB{ refA { a }}
}
}
```
and expect the gateway to fetch these completely by single call to services B and C respectively.
But the gateway fails to compose the three schemas with error
```
This data graph is missing a valid configuration. [C] B.refA -> marked @external but refA was defined in B, not in the service that owns B (B)
```
If I try to compose just A and B it works fine and the first query from above gets fetched completely from B as expected.
My real use case is that A are some metadata, B are entities like users and C are dynamic events these users produce. For performance I want to have some often used fields from A (there are many in the real case, for brevity I put just one here) copied both into records stored in B and C so that I don't have to join with A all the time. My service implementations are java using graphql-java so I can't use `extend` keyword but have to use the `@extends` annotation should that have any relevance.
I'm not sure if this is supposed to work at all but did not find anything in the documentation which would seem to indicate it shouln't.
Runnable reproduction scenario can be found here: https://github.com/wheene/apollo-gatewat-provides-issue
* "apollo-server": 2.13.1
* "@apollo/gateway": 0.16.0
Thanks for the great project that is Apollo!
Contributor guide
Research direction
Start with the runnable reproduction scenario linked in the issue and compare composition of services A and B with composition of A, B, and C. Trace the gateway's schema-composition error for C's external B.refA field; done means the three schemas compose and the shown queries can be fetched from B and C without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 32/100