Using Apollo Federation V2. In my gateway, creating context as follows;
context: ({ req }) => {
if (req.user) {
const user = req.user;
return { user };
} else {
console.error(
'Authentication error while creating GQL Context',
new Date().toLocaleTimeString(),
);
throw new Error('Authentication error while creating GQL Context');
}
},
gateway is expecting a validated request to pass it throu.
I need to add a Login
mutation to my auth
subgraph. Naturally, the user who tries to login, is not yet authenticated!.
I need a way to tell the gateway not to check authentication for login
mutation.
I considered using custom directives. However, since the custom directives are specific to subgraphs, they are not included in composed supergraph, as Apollo Docs says.
What would be the best option to set authentication on or off in gateway depending on the query or mutation?