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 month 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