-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose sub-query DocumentNode to RemoteGraphQLDataSource#willSendRequest hook #1352
Comments
It's worth noting that we would also want to mutate the query (remove any fields that fail the authorization check). |
I believe the original reason for keeping the query as a string in the query plan is to avoid having to reserialize it on every requests, as the change of point 4) above would entail. And I do think it's an "optimisation" worth preserving "in general", but of course that doesn't necessarily preclude from having different paths for different cases. That said, I'd like to dig into this a bit more first because ...
I think this is a very very dangerous idea and I really don't think this is something federation should attempt to officially support. Query plans can be somewhat complex, and the inputs of some of the queries in a plan routinely depend on the result of a previous query, so mutating the queries can extremely easily break things (and as federation evolves and we add more "smarts", this will not get better), and I can too easily see it breaking it in ways that are very hard to debug. I could see how having the queries to services as a read-only I'll note that taking a step back, if I was trying to enforce permission/authorisation at the gateway level, I'd try to enforce it at the user-query level, before it gets passed to the gateway for query-planning/execution (the alternative being to enforce it within each services, though you can certainly mix both). But obviously you may have specific constraints I ignore and I'm happy to help dealing with those in a way that don't involve mutating the service queries :). |
Thanks for the detailed response @pcmanus ! I agree that mutating the subgraph request is fraught, especially when it comes to fields used in Taking a step back to look at all the possible Policy Enforcement Points (PEP) along the request path:
here's my off-the-cuff evaluation of each:
After that exercise, it's not any clearer to me where the PEP should go 😁. I see two options potential options for prototyping an authz solution:
Long term, I like either option number 1, or building new functionality in the query planner for redacting fields from subgraph calls. This does not meet the requirement of enforcing authz for direct subgraph calls that skip the router, but that might just be out of scope for Apollo. |
Thank you for this great analysis and feedback both Sylvain and Lenny, to help make sure we dont shoot ourselves in the foot. I would like to +1 on the original ask for having the sub-query document AST exposed, but for read-only use only (for usage scenarios that doest need to mutate) to prevent customers having to pay the additional toll of re-parsing. |
Currently sub-query generated for each
RemoteGraphQLDataSource
needed to complete the query is passed toRemoteGraphQLDataSource
as a string, which limits possible interactions with the query on #willSendRequest level, e.g. introducing custom permission checking on field/type level.Generated
DocumentNode
is immediately serialized into string, see buildPlan.ts#L803, and exposing it won't cause additional performance toll.In order to achieve this I propose:
operation
field of typeDocumentNode
instead ofstring
.DocumentNode
instead ofstring
.GraphQLDataSourceProcessOptions
to haveDocumentNode
included:GraphQLDataSource#process
calls to fit newGraphQLRequestContext
definition:The text was updated successfully, but these errors were encountered: