Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Apollo Federated GraphQL, is there a way to sort/paginate on a value from an external entity?

Is it possible to mark a field in an input to a query as requiring a field extended by a different service?

Using the federation-demo to illustrate my question, but keeping a little bit more simple. Having just an Account service and a Reviews service, and adding a karma field to the User, is it possible to filter reviews based on User karma.

Account service, adding a karma int to a User:

  extend type Query {
    me: User
  }
  type User @key(fields: "id") {
    id: ID!
    name: String
    username: String
    karma: Int!
  }

Reviews service, adding a reviews Query:

  extend type Query {
    reviews(minKarma: Int): [Review!]!
  }
  type Review @key(fields: "id") {
    id: ID!
    body: String
    author: User @provides(fields: "username")
    product: Product
  }
  extend type User @key(fields: "id") {
    id: ID! @external
    username: String @external
    karma: Int! @external
    reviews: [Review]
  }
  extend type Product @key(fields: "upc") {
    upc: String! @external
    reviews: [Review]
  }

In my resolver for Query.reviews, I want to filter out any review where review.author.karma is less than the specified minKarma.

How do I tell the gateway that when minKarma is specified in the Query input, I want the Account service to be queried first and a representation of users to be passed into the Reviews service, with the karma of each user attached to the review as the author, so that I can do the filter?

Circling back to the question at the top of this post, can I mark the minKarma field as requiring User.karma?

like image 989
onthegojohn Avatar asked Nov 06 '22 04:11

onthegojohn


1 Answers

This is the questions plaguing me as well.

like image 187
Andrew Obrigewitsch Avatar answered Dec 14 '22 03:12

Andrew Obrigewitsch