apollographql / apollographql/federation
Federation does not appreciate specified nested fields in @provides directive
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
## Use case
Let's assume we have three sub-graphs (services) in federated graph:
- Company
- for authorized access by a small amount of users
- uses sql db for companies
- Vacancy
- for authorized access by a small amount of users
- uses sql db for vacancies
- PublicVacancySearch
- for massive public search by a huge amount of users
- uses non-sql db for public vacancy search
- has denormalized data of company as part of vacancy document that is synchronized via message broker or job
## Schemas
Below are the results of `{ _service { sdl } }` queries.
Company sub-graph
```gql
type Company @key(fields: "id") {
id: ID!
name: String!
logoUrl: String!
}
```
Vacancy sub-graph
```gql
type Vacancy @key(fields: "id") {
id: ID!
title: String!
company: Company!
}
extend type Company @key(fields: "id") {
id: ID! @external
}
type Query {
myVacancies(MyVacanciesInput! input): MyVacanciesOutput!
}
type MyVacanciesOutput {
totalCount: Int!
items: [Vacancy!]!
}
```
PublicVacancySearch sub-graph
```gql
type Vacancy @key(fields: "id") {
id: ID! @external
title: String! @external
company: Company! @external
}
extend type Company @key(fields: "id") {
id: ID! @external
name: String! @external
logoUrl: String! @external
}
type Query {
publicVacancies(input: PublicVacanciesInput!): PublicVacanciesOutput!
}
type PublicVacanciesOutput {
totalCount: Int!
items: [Vacancy!]! @provides(fields: "title company { name logoUrl }")
}
```
## The goals
The goals are
- reuse the same Vacancy type in schema
- resolve normalized vacancy and company data from different sql databases for `myVacancies` query
- resolve denormilized vacancy and company data from single non-sql database.
So, in composed schema I want to make the following queries and expect the following behaviour.
```gql
{
myVacancies(input: { ... }) {
totalCount
items {
id # resolve from vacancy sql db
title # resolve from vacancy sql db
company {
id # resolve from vacancy sql db
name # resolve from company sql db
logoUrl # resolve from company sql db
}
}
}
publicVacancies(input: { ... }) {
totalCount
items {
id # resolve from public vacancy search non-sql db
title # resolve from public vacancy search non-sql db
company {
id # resolve from public vacancy search non-sql db
name # resolve from public vacancy search non-sql db
logoUrl # resolve from public vacancy search non-sql db
}
}
}
}
```
## The problem
Apollow gateway is throwing the following error when tries to compose schema:
```
This data graph is missing a valid configuration.
[PublicVacancySearch] Company.name -> is marked as @external but is not used by a @requires, @key, or @provides directive.
[PublicVacancySearch] Company.logoUrl -> is marked as @external but is not used by a @requires, @key, or @provides directive.
```
## Additional information
```
"@apollo/gateway": "^0.19.0"
"apollo-server": "^2.16.1"
```
According to docs, `@provides` directive should be able to accept nested fields.
https://www.apollographql.com/docs/federation/federation-spec/#provides
https://www.apollographql.com/docs/federation/federation-spec/#scalar-_fieldset
But I have already tried various different combinations of `@provides` directive usage, and they aren't successful.
For now I have found only one similar issue.
https://spectrum.chat/apollo/apollo-federation/nested-provides-field-solution~72caeda3-48c9-4dd8-9b98-69c19a8afdb5
Maybe I miss something, but for now I am stuck.
I will appreciate any help.
Contributor guide
Research direction
The reproduction is the three SDLs in the issue and composition through @apollo/gateway 0.19.0; start by running that composition with the shown schemas and reading the linked federation @provides and _FieldSet specifications. Done means the nested company fields compose with the intended behavior, or the supported behavior and limitation are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100