Hello! Is my first approach to graphql federation, I’m trying to understand what can I do (and how) with the directives.
So, let’s consider a simple supergraph example composed by 2 graphs: auth and profiles.
auth store login information, and profiles things like billing and shipping address, company and user profiles.
In the auth schema I have:
type LegalIdentiy @key(fields: "identity_id", resolvable: false) {
identity_id: ID!
}
type OrganicGroup @key(fields: "og_id") {
og_id: Int!
name: String
legalIdentiy: LegalIdentiy
}
and auth resolver for OrganicGroup entity:
OrganicGroup: {
legalIdentiy: async (reference, _context) => {
/* some logic */
return {
identity_id: reference.og_id.toString(),
};
},
},
and then the profiles graph:
type LegalIdentiy @key(fields: "identity_id") {
identity_id: ID!
identity_type: String
legal_name: String
street_name: String
}
with his resolver:
LegalIdentiy: {
__resolveReference: (reference, a) => {
/* some logic that populate result*/
return {
identity_id: result.id,
identity_type: result.type,
legal_name: result.legal_name,
street_name: result.street_name
};
},
},
now the question is, how do I pass arguments from the auth’s OrganicGroup field resolver to the profiles LegalIdentity one?
Those arguments should not be part of the query, and may trigger some logic in profile’s __resolveReference function.
So far i’ve been able to do this only using @inaccessible directive, so in my auth example become:
type LegalIdentiy @key(fields: "identity_id extra_args", resolvable: false) {
identity_id: ID!
extra_args: String @inaccessible @shareable
}
and the auth resolver:
OrganicGroup: {
legalIdentiy: async (reference, _context) => {
return {
identity_id: reference.og_id.toString(),
extra_args: "custom value from auth subgraph!",
};
},
},
then the profiles graph become:
type LegalIdentiy @key(fields: "identity_id extra_args") {
identity_id: ID!
extra_args: String @inaccessible @shareable
identity_type: String
legal_name: String
}
…and in his resolver I can finally get extra_args value:
LegalIdentiy: {
__resolveReference: (reference, a) => {
/* reference.extra_args has the value from auth subgraph! */
return {
identity_id: result.id,
identity_type: result.type,
legal_name: result.legal_name,
street_name: result.street_name
};
},
},
but even if it works so far, looks like a bit tricky/hacky to me.
So, there is a better way to achieve this result?