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.