apollographql / apollographql/federation

@requires field always resolved from same subgraph

Open
#2,801 5 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
727
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

### Issue Description

If one subgraph @requires a field to resolve another field, and that other field is @shareable defined in multiple subgraphs, the query plan seems to arbitrarily pick one subgraph to resolve the shareable field everytime.

This results in a less performant query plan because even if the subgraph that is resolving the query can resolve the @shareable field as well, the query plan still includes the third subgraph just to resolve the shareable field.

Included in the reproduction project I also use @provides to explicitly provide the required field and yet it is still not resolved from the expected subgraph.

I would expect that @shareable would build the most efficient query plan automatically, but especially would expect it when explicitly defining the query plan by using `@provides`.

### Link to Reproduction

https://github.com/joshfoeh-bill/apollo-query-plan

### Reproduction Steps

Reproduction steps included in readme of attached repo.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the README in the linked reproduction repository and reproduce the query plan involving @requires, @shareable, and @provides. Done means the plan selects the subgraph that can resolve the required shareable field when that avoids an unnecessary third-subgraph fetch, including the explicit @provides case.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.