apollographql / apollographql/federation
[Feature Request] New Directive for primary keys in the Query
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Hi Team,
From the query plan which I added below, we can see that Apollo Gateway is waiting for SA(Service A) to respond even when we are providing the primary key(appNo) of the return type of a query as a param.
We want to call SA and SB parallelly when a client uses a query with primary key/keys of a return type as an input. So I'm requesting to introduce a new annotation, which helps Apollo Gateway identify if the client variables are the primary keys of a query return type. I think this helps Apollo Gateway to make calls parallelly to SA and SB and achieve more performance.
**SA - Schema**
```
type App @key(fields: "appNo" ) {
appNo: Int!
name: String!
}
type Query {
getApp (appNo: Int!): App
}
```
**SB - Schema**
```
type App @key(fields: "appNo" ) @extends {
appNo: Int! @external
description: String!
}
```
**Client Request to Apollo Gateway**
```
query {
getApp(appNo: 1) {
appNo
name
description
}
}
```
**Query Plan of Gateway for the above request**
```
QueryPlan {
Sequence {
Fetch(service: "SA") {
{
getApp(appNo: 1) {
name
__typename
appNo
}
}
},
Flatten(path: "getApp") {
Fetch(service: "SB") {
{
... on App {
__typename
appNo
}
} =>
{
... on App {
description
}
}
},
},
},
}
```
Contributor guide
Research direction
Start by reviewing the Apollo Gateway query plan and the SA/SB federation schemas in the issue. Determine how a directive would identify primary-key query inputs and change the plan from a sequence to parallel fetches. Done means the behavior is specified and covered by query-planning tests, but the issue names no files or tests to begin with.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100