https://kotlinlang.org logo
Title
s

Saharath Kleips

04/26/2022, 8:30 PM
Hey ya’ll I have a question related to setting up Federation (extensions?) that I could use some direction on. We have two entities that look like this: •
Box
◦ id ◦ size ◦ … ◦ shape ids •
Shape
◦ id ◦ type ◦ …
Box
and
Shape
are served by two independent services. Can we (or does it make sense to) have
Shape
“extend”
Box
to “fully resolve” shapes for a given box?
d

Dariusz Kuc

04/26/2022, 9:06 PM
what is the relationship between the types? using Apollo Federation you can extend types with additional fields i.e. (omitting directives and some types for simplicity)
// service A
type Query {
  foo: Foo
}

type Foo {
   id: ID
   bar: Bar
   baz: Baz
}

// service B
extend type Foo {
   id: ID // key
   qux: QUX
   quux QUUX
}
note: there is no query available in service B it extends a type from service A with additional fields
s

Saharath Kleips

04/26/2022, 9:36 PM
It would be something like:
// service A
type Query {
  foo: Foo
}

type Foo {
  id: ID
  barIDs: [ID]
  ...
}

// service B
type Bar {
  id: ID
  ...
}

extend type Foo {
  bars: [Bar]
}
If that makes sense?
So the relationship isn’t like, Service B can extend Foo given a Foo ID, it’s more like Foo already has barIDs as part of its model, and Service B can use those to “resolve” the relationship
d

Dariusz Kuc

04/26/2022, 10:00 PM
Federation is based around uniquely identifying your entities based on some key/keys
I guess of you were to define your key field set as "id barIds" it could work (but imho model would be clearer if those bar service would return the list based on foo id only)
s

Saharath Kleips

04/26/2022, 10:03 PM
Let me try that approach — I think your suggestion definitely fits more inline with the federation examples I’ve been seeing. Will chat to see if that’s a practical option for us 👍
s

Shane Myrick

04/26/2022, 10:13 PM
if you already have the
Box.shapeIds
as a field you could have the shape-service extend the
Box
type to add a new field
shapes: [Shape] @requires(fields: "shapeIds")
so you could resolve the list of ids in one call
🤔 1
s

Saharath Kleips

04/26/2022, 10:16 PM
https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/federation/federated-directives/#requires-directive this definitely sounds closer to what we’re trying to accomplish 👍 will report back