5

I am new to apollo and I have two apollo service that I want to federate by using apollo federation:

Productservice:

extend type Query {
  job(id: String!): Job
}

type Seo {
  title: String! 
  description: String! 
  keywords: String! 
}

type Product @key(fields: "id")  {
  id: ID!
  title: String!
  seo: Seo!
}

StaffService:

extend type Query {
  staffMember(id: String!): StaffMember
}

type Seo {
  title: String! 
  description: String! 
  keywords: String! 
}

type StaffMember @key(fields: "id")  {
  id: ID!
  title: String!
  seo: Seo!
}

How can I use the type Seo in response objects of both objects? Is the correct procedure to create an interface Seo and implement StaffMemberSeo and ProductSeo or is there an annotation that allows me to define the exactly same type within two services?

simsi
  • 533
  • 3
  • 16
  • `Seo` should be included in the `seo` field of the query result. Are you asking how to have its fields unnested directly in the query result and not nested in the `seo` field? – Oluwafemi Sule Mar 01 '20 at 07:15
  • 1
    No, the question is about having defined Seo two times. I think the answer to the question is that the design of apollo doesn't allow it and I have to rename Seo to StaffSeo and ProductSeo. – simsi Apr 19 '20 at 15:57

1 Answers1

3

One service must own the type. In that service use the @key directive. In the referencing services use @extend, and include a stub of the type with fields used by that service.

Think of this as like a foreign key in a SQL database.

Mike Lyons
  • 22,575
  • 2
  • 16
  • 19