graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Federation: handle distributed unions and interfaces that do not shar…

Open ardatan opened this issue 1 year ago • 2 comments

Handle interface types with non-shared implementations;

For example, you have the following services, where Node is implemented in both services, but Foo and Bar are only implemented in one service. And when the gateway receives the following query, it should be converted to this because Node is not implemented as Bar in Service 1 while implemented in Service 2.

Query conversion;

# Gateway request
query {
  fooBar(id: "1") {
    ... on Node {
      id
    }
  }
}
# Service 1 Request
query {
  fooBar(id: "1") {
    ... on Foo {
      id
    }
    ... on Bar {
      id
    }
  }
}

Services;

# Service 1

union FooBar = Foo | Bar

interface Node {
  id: ID!
}

type Foo implements Node {
  id: ID!
}

type Bar {
  id: ID!
}

type Query {
  fooBar(id: ID!): FooBar
}
# Service 2
interface Node {
  id: ID!
}

type Foo implements Node {
  id: ID!
}

type Bar implements Node {
  id: ID!
}

ardatan avatar May 16 '24 16:05 ardatan

🦋 Changeset detected

Latest commit: 2d6d4662583e2d6ac1cce26995e8f461000b1ab5

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

This PR includes changesets to release 3 packages
Name Type
@graphql-tools/federation Patch
@graphql-tools/delegate 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

changeset-bot[bot] avatar May 16 '24 16:05 changeset-bot[bot]

✅ Benchmark Results

     ✓ no_errors
     ✓ expected_result

     checks.........................: 100.00% ✓ 338       ✗ 0  
     data_received..................: 39 MB   3.9 MB/s
     data_sent......................: 145 kB  14 kB/s
     http_req_blocked...............: avg=3.91µs   min=2.06µs   med=2.55µs  max=182.28µs p(90)=3.72µs   p(95)=4.19µs  
     http_req_connecting............: avg=721ns    min=0s       med=0s      max=121.92µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=55.24ms  min=47.67ms  med=51.71ms max=153.62ms p(90)=59.21ms  p(95)=85.67ms 
       { expected_response:true }...: avg=55.24ms  min=47.67ms  med=51.71ms max=153.62ms p(90)=59.21ms  p(95)=85.67ms 
     http_req_failed................: 0.00%   ✓ 0         ✗ 169
     http_req_receiving.............: avg=127.68µs min=100.14µs med=125.7µs max=268.18µs p(90)=142.64µs p(95)=150.84µs
     http_req_sending...............: avg=26.3µs   min=18.44µs  med=24.09µs max=336.51µs p(90)=30.56µs  p(95)=33.7µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s      max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=55.09ms  min=47.53ms  med=51.55ms max=153.3ms  p(90)=59.04ms  p(95)=85.5ms  
     http_reqs......................: 169     16.796765/s
     iteration_duration.............: avg=59.51ms  min=51.35ms  med=55.91ms max=159.36ms p(90)=65.98ms  p(95)=90.14ms 
     iterations.....................: 169     16.796765/s
     vus............................: 1       min=1       max=1
     vus_max........................: 1       min=1       max=1

github-actions[bot] avatar May 16 '24 16:05 github-actions[bot]

🚀 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/delegate 10.0.11-alpha-20240517140204-2d6d4662583e2d6ac1cce26995e8f461000b1ab5 npm ↗︎ unpkg ↗︎
@graphql-tools/federation 1.1.36-alpha-20240517140204-2d6d4662583e2d6ac1cce26995e8f461000b1ab5 npm ↗︎ unpkg ↗︎
@graphql-tools/stitch 9.2.9-alpha-20240517140204-2d6d4662583e2d6ac1cce26995e8f461000b1ab5 npm ↗︎ unpkg ↗︎
@graphql-tools/utils 10.2.1-alpha-20240517140204-2d6d4662583e2d6ac1cce26995e8f461000b1ab5 npm ↗︎ unpkg ↗︎

github-actions[bot] avatar May 17 '24 14:05 github-actions[bot]

💻 Website Preview

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

github-actions[bot] avatar May 17 '24 14:05 github-actions[bot]