简体   繁体   中英

How to handle child objects extension in Apollo Federation

Service A:

type A {
  id: ID!
  embeddedMetaData: MetaData
}
type MetaData{
  fieldA: String
}

Service B:

type A  @key(fields: "id") {
  id: ID! @external
  #I want to extend and resolve a new field into MetaData type without overriding
}

How can I extend embedded object without overriding any other fields and leaving the resolution of the other fields in the A service?

You can extend type A in service B, by first making type A extendable:

Service A

type A @key(fields: "id") {
 id: ID!
  embeddedMetaData: MetaData
}
type MetaData{
 fieldA: String
}

Type A is now an entity. You can add new fields on type A that will be resolved by service B following below:

Service B

extend type A  @key(fields: "id") {
  id: ID! @external
  newField: String
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM