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

No unnecessary inline fragment spreads for union types in federation and link dependencies #5913

Merged
merged 13 commits into from Feb 23, 2024

Conversation

enisdenjo
Copy link
Collaborator

@enisdenjo enisdenjo commented Feb 19, 2024

Link dependencies

Many of the dependencies in the monorepo are not linked and therefore not updated on new releases. They should! (Note that I haven't checked all deps, only those affected by this PR.)

Inline fragment spread

# supergraph.graphql

[...]

type Query @join__type(graph: ACCOUNTS) {
  fooBar: FooBar
}

union FooBar
  @join__type(graph: ACCOUNTS)
  @join__unionMember(graph: ACCOUNTS, member: "Foo")
  @join__unionMember(graph: ACCOUNTS, member: "Bar")

type Foo @join__type(graph: ACCOUNTS, key: "id") {
  id: ID!
  name: String
}

type Bar @join__type(graph: ACCOUNTS, key: "id") {
  id: ID!
  name: String
}
# gateway-query.graphql

{
  fooBar {
    ... on Foo {
      name
    }
    ... on Bar {
      name
    }
  }
}
# ACCOUNTS-query.graphql

query {
  __typename
  fooBar {
-   ... on FooBar
      ... on Foo {
        name
      }
      ... on Bar {
        name
      }
-   }
    __typename
  }
}

Copy link

changeset-bot bot commented Feb 19, 2024

🦋 Changeset detected

Latest commit: b27ae86

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@graphql-tools/apollo-engine-loader Patch
@graphql-tools/batch-delegate Patch
@graphql-tools/batch-execute Patch
@graphql-tools/delegate Patch
@graphql-tools/executor Patch
@graphql-tools/executor-apollo-link Patch
@graphql-tools/executor-envelop Patch
@graphql-tools/executor-graphql-ws Patch
@graphql-tools/executor-http Patch
@graphql-tools/executor-legacy-ws Patch
@graphql-tools/executor-urql-exchange Patch
@graphql-tools/executor-yoga Patch
@graphql-tools/federation Patch
@graphql-tools/github-loader Patch
@graphql-tools/graphql-file-loader Patch
@graphql-tools/import Patch
@graphql-tools/json-file-loader Patch
@graphql-tools/links Patch
@graphql-tools/load Patch
@graphql-tools/merge Patch
@graphql-tools/mock Patch
@graphql-tools/module-loader Patch
@graphql-tools/node-require Patch
@graphql-tools/prisma-loader Patch
@graphql-tools/relay-operation-optimizer Patch
@graphql-tools/resolvers-composition Patch
@graphql-tools/schema Patch
@graphql-tools/stitch Patch
@graphql-tools/stitching-directives Patch
@graphql-tools/url-loader Patch
federation-benchmark Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 19, 2024

✅ Benchmark Results

     ✓ no_errors
     ✓ expected_result

     checks.........................: 100.00% ✓ 312       ✗ 0  
     data_received..................: 36 MB   3.6 MB/s
     data_sent......................: 134 kB  13 kB/s
     http_req_blocked...............: avg=4.03µs   min=2.09µs   med=2.71µs   max=174.56µs p(90)=3.85µs  p(95)=4.26µs  
     http_req_connecting............: avg=739ns    min=0s       med=0s       max=115.4µs  p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=60.18ms  min=46.63ms  med=56.56ms  max=144.98ms p(90)=68.73ms p(95)=94.05ms 
       { expected_response:true }...: avg=60.18ms  min=46.63ms  med=56.56ms  max=144.98ms p(90)=68.73ms p(95)=94.05ms 
     http_req_failed................: 0.00%   ✓ 0         ✗ 156
     http_req_receiving.............: avg=138.19µs min=103.83µs med=133.65µs max=270.11µs p(90)=157µs   p(95)=172.16µs
     http_req_sending...............: avg=30.28µs  min=19.94µs  med=24.94µs  max=717.94µs p(90)=31.69µs p(95)=35.84µs 
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=60.01ms  min=46.48ms  med=56.39ms  max=144.65ms p(90)=68.57ms p(95)=93.87ms 
     http_reqs......................: 156     15.539356/s
     iteration_duration.............: avg=64.32ms  min=51.28ms  med=60.77ms  max=160.04ms p(90)=75.45ms p(95)=98.08ms 
     iterations.....................: 156     15.539356/s
     vus............................: 1       min=1       max=1
     vus_max........................: 1       min=1       max=1

Copy link
Contributor

github-actions bot commented Feb 19, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-tools/batch-delegate 9.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/batch-execute 9.0.4-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/delegate 10.0.4-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor 1.2.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-apollo-link 1.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-envelop 2.0.4-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-graphql-ws 1.1.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-http 1.0.9-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-legacy-ws 1.0.6-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-urql-exchange 1.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/executor-yoga 2.0.4-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/federation 1.1.17-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
graphql-tools 9.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/import 7.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/links 9.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/load 8.0.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/apollo-engine-loader 8.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/github-loader 8.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/graphql-file-loader 8.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/json-file-loader 8.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/module-loader 8.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/prisma-loader 8.0.3-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/url-loader 8.0.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/merge 9.0.3-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/mock 9.0.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/node-require 7.0.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/relay-operation-optimizer 7.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/resolvers-composition 7.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/schema 10.0.3-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/stitch 9.0.5-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/stitching-directives 3.0.1-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎
@graphql-tools/wrap 10.0.2-alpha-20240222154539-b27ae8605c354eed2b24844a475c8889ccc90dfb npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Feb 19, 2024

💻 Website Preview

The latest changes are available as preview in: https://d9ff513e.graphql-tools.pages.dev

@enisdenjo enisdenjo changed the title No unnecessary inline fragment spreads for union types in federation No unnecessary inline fragment spreads for union types in federation and link dependencies Feb 22, 2024
type = isNonNullType(type) ? type.ofType : type;
if (
type != null &&
isAbstractType(getNamedType(type)) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to spread on abstract type ?
Shouldn't the spread be inside the selection set of this type, to spread inline fragment for each final types possible ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100%, I just know that we need to spread interfaces and the _Entity union. Omitting either (or both) fails a bunch of data-fetching tests. Maybe @ardatan can shine some light. :D

@enisdenjo enisdenjo merged commit 83c0af0 into master Feb 23, 2024
30 checks passed
@enisdenjo enisdenjo deleted the fragment-union branch February 23, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants