Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse named fragment in subgraphs even if they only apply partially #2639

Merged
merged 2 commits into from
Jun 27, 2023

Commits on Jun 23, 2023

  1. Reuse named fragment in subgraphs even if they only apply partially

    The focus of the code reusing fragment has been thus far on making
    that if a given named fragment can be used in a given selection set,
    then the code finds it. But in practice, the named fragments we try
    to reuse are those of the input query, so defined against the
    supergraph API schema, while we're trying to reuse them on subgraph
    fetches, so the fragment may be defined on a type that a subgraph
    does know, or request fields the subgraph does not define.
    
    Currently, when asking if a given named fragment can be used against
    a given subgraph, we only keep fragment that _fully_ apply to that
    subgraph (that is, only if everything the fragment queries exists
    in the subgraph).
    
    This does limit the usefulness of named fragment reuse however, as one
    of the point of federation is that each subgraph defines a subset
    of the full supergraph API.
    
    This commit improves this by instead computing the subset of each
    named fragment that do apply to a given subgraph, and define the
    fragment as only that fragment for the subgraph.
    
    Note that it does so, this commit do not try reusing a named fragment
    against a subgraph if the subset of the fragment on the subgraph
    comes to only a single leaf field. This avoids spending time trying
    to reuse a fragment that ends up being just:
    ```graphql
    fragment MySuperFragment on X {
      __typename
    }
    ```
    or even:
    ```graphql
    fragment MySuperFragment on X {
     id
    }
    ```
    as those aren't productive (the goal of fragment reuse is to try to
    make the subgraph fetches smaller, but it is small to just request
    `id`, even 10 times, than to request 10 times `...MySuperFragment`).
    pcmanus committed Jun 23, 2023
    Configuration menu
    Copy the full SHA
    d9fd30a View commit details
    Browse the repository at this point in the history

Commits on Jun 27, 2023

  1. Fix typos/grammatical errors

    pcmanus committed Jun 27, 2023
    Configuration menu
    Copy the full SHA
    f4172d4 View commit details
    Browse the repository at this point in the history