Filtering on fields across multiple subgraphs

Hello,
Currently I’m working on a POC to migrate some of our frontend api’s to GraphQL with federation.

In one of the use cases I have the following two subgraphs(simplified for the sake of abbreviation).

# Organisation subgraph
type Query {
    organisationById(organisationId: ID!): Organisation
}

type Person @key(fields: "id") {
    id: ID!
    firstName: String
		lastName: String
		dateOfBirth: LocalDate!
	  organisation: Organisation
}

type Organisation {
    id: ID!
    name: String!
    user: [Person]!


# Authorization subgraph
type Person @key(fields: "id"){
    id: ID!
    roles: [Role!]!
}

type Role {
    id: ID!
    rolNaam: String!
    users: [Persoon]
}

type Query {
    userByRole(typeNaam: String!): Persoon
}

The subgraphs don´t share the same datasource. In fact, the authorization subgraph is connected to a 3rd party authorization provider.

Question 1
Our system has over 100 Organisations, each with tens of users. I want to query all persons having a certain role(say: organisation-administrator) within a given Organisation. So I want to define a query in one subgraph an limit the results by filtering on a field in another subgraph.

I also tried the suggestions with a combination of @required and @external directives but couldn’t really figure out how.

Question 2
From what I understand about federation I doubt if this is possible. Both subgraphs add and resolve their own fields on the Person type. When I query persons with a certain role, the Authorization subgraph resolves all persons with this role for all organisations.

When technically possible, the organisation subgraph would only resolve persons belonging to 1 Organisation. This would make the response inconsistent, because both subgraphs resolve a different number of persons.

Am I correct?

I’m using Apollo Server as Gateway and Spring-GraphQL for the subgraphs.

Hey there @steffen ! Have you taken a look at this article? Aggregating Data Across Subgraphs. It seems like your use case is similar to what’s defined in the article. Hope it helps!

Hello Michele,

Thank you for your answer. It looks like the documentation you linked describes the same use case. The solution is not really one I was hoping for, but I understand why it works that way. It looks like we nee some kind of BFF for the subgraph’s which is the pattern I’m trying to get rid of by introducing GraphQL. But I’look into it.

Regards,
Steffen