GraphQL execution should begin after authentication middleware confirms the user’s identity and passes that information to the GraphQL layer. But after that, you still need to determine if the authenticated user is allowed to view the data provided by the specific fields that were included in the request.
Imagine you're building a blogging platform where users can only edit their own posts. How would you pass the user's session token from an HTTP header down to a specific GraphQL resolver to verify their identity before saving?
We have a query that returns a list of users, but only admins should see the 'email' field. If a regular user queries the list, how would you handle hiding just that specific field while still returning the rest of the user data?
We currently have authorization checks duplicated inside twenty different resolvers. A teammate suggests moving this logic into custom schema directives like '@auth(role: ADMIN)'. What are the pros and cons of this approach, and how would you handle cases where the auth check depends on database data, like checking if a user owns a document?
A client app queries a dashboard with 5 different nested fields. One of those fields fails an authorization check. How would you structure the GraphQL error response so the client can still render the other 4 fields, and how do you prevent the client from breaking on null values?
In a federated GraphQL architecture, we need to enforce authorization. How do you decide which auth checks happen at the gateway level versus downstream in the individual subgraphs, especially when a single client query spans multiple microservices?
We noticed a major performance degradation on a query that returns a list of 100 items. It turns out our field-level authorization directive is making an independent database call for every single item to check permissions. How would you refactor this to avoid the N+1 authorization problem?
We are migrating a legacy monolithic REST API with centralized OAuth2 and Open Policy Agent (OPA) to a federated GraphQL graph managed by 15 different product teams. How would you design a unified authorization framework that ensures consistent security policies across all teams without bottlenecking their deployment velocity?
As our graph has grown, we've ended up with a mix of directive-based auth, resolver-level checks, and gateway-level blocking. This has led to security audits finding leaked fields. How would you design a declarative, auditable authorization strategy for the entire enterprise graph that can be statically analyzed before code is merged?