How to Filter in graphql query correctly?

I will not say it is the wrong way, but it may not be the most efficient way. Consider if your graph had millions of profiles. Your query would traverse a million profiles to a million users and then filter those users to just the one you wanted and then remove all profiles except the one and return the response.

The better way to query a graph is start with the smallest known group of nodes, or single node, first.

query QueryUserProfile($userId: String!){
  getUser(id:$userId) {
    id
    profile {
      id
      fullName
      avatarPictureURL
      coverPictureURL
      city
    }
  }
}
1 Like