Skip to content

Instantly share code, notes, and snippets.

@ramapalani
Last active October 11, 2022 04:06
Show Gist options
  • Save ramapalani/57912046640c632e242ecf7f8564d5a6 to your computer and use it in GitHub Desktop.
Save ramapalani/57912046640c632e242ecf7f8564d5a6 to your computer and use it in GitHub Desktop.
How to pass Arguments of a two level higher type across Subgraphs

How to pass argument of a two level higher type across subgraphs?

Subgraph1 (Show) Schema

extend schema
  @link(url: "https://specs.apollo.dev/federation/v2.0",
        import: ["@key", "@shareable"])

type Show @key(fields: "id"){
    id: ID!
    title: String
    releaseYear: Int
}

type Query {
    shows(releaseYear: Int): [Show!]! 
}


Subgraph2 (Review) Schema

type Show @key(fields: "id") {
    id: ID!
    reviews: [Review!]! 
}
type Review {
    user: User
    starScore: Int
    submittedDate: DateTime
}
type User {
    id: ID!
    name: String!
    joinedDate: DateTime
}

User Query

query {
  shows (releaseYear: 2022) {
    title
    reviews {
      user {
        name
        joinedDate
      }
      submittedDate
    }
  }
}

Is there a way in Apollo Federation2 to pass the argument releaseYear provided at the field shows to child fields reviews and grand child field user that are in a different subgraph?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment