-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ApolloServerPlugin should be get info about the actual Query/Mutation, not just the Operation #4910
Comments
I'm a bit confused about your terminology here. I think when you say by "query field definition" you mean what we usually call the "schema"? The GraphQLRequestContext passed to all the handlers does contain A different approach to your problem is that you could have a special scalar type |
@glasser The schema is available in the request context, however, the code snippet you provided would not work without re-parsing the operation passed on the context. requestContext.schema.getType("Query")?.getFields()["getAFoo"]?.astNode?.directives The missing piece of information preventing me from using this snippet is the string The only way I can see getting this working right now would be to somehow parse The scalar type I apologize for using any confusing terminology, when dealing with graphQL it can be struggle to just not use the work 'query' for everything haha. |
oh, additionally, the context currently only has info on the variables associated with the operation, not the query arguments. Using a modified version of the operation I included above:
The context currently has info on the variable |
You can find the rest of the parsed query from the OperationDefinitionNode by looking under So what you want to do is walk the operation's tree while using the GraphQLSchema to understand the types that you're looking at. |
@glasser looks like Also, I had originally wanted to put the directive on the argument definition but unfortunately we are using type-graphql and they don't yet support directives on arguments: MichalLytek/type-graphql#77 (comment). I think there is some work on the spec going on rn to make it so that certain directive types are available outside of the SDL. |
I'm trying to implement a directive + plugin combo for safe logging. Roughly the idea being that you can add a
@logSafe
directive to a query/mutation definition that would allow you to declare what arguments are safe to log. For example:Which would allow one to implement a
ApolloServerPlugin
that could log information about a request in theexecutionDidStart
lifecycle hook checking the@logSafe
directive for whether or not a given argument is safe to log.The issue with this approach is that
ApolloServerPlugin
lifecycle hooks only get the operation definition not the query definition, which looks like the following:The plugin receives the following information on operations.
The above
directives
array only contains directives declared on the operation which is usually declared client side, so not suitable for the safe logging use case.Additionally, there does not seem to be a good way to get from operation definition to query field definition, which would contain the correct directives. The only way I could see to do it right now is to somehow manually parse the source of the operation for the relevant queries, then check against the schema. This feels pretty error prone, additionally would have a perf cost since we would be parsing the operation twice, once by apollo and a second time by this plugin.
Ideally the
executionDidStart
lifecycle hook could receive a list of parsed queries and their relevant metadata. Even getting access to the relevantGraphQLField
for the queries would be good enough, since then I could add something to the extension field via an apollo schema visitor.The text was updated successfully, but these errors were encountered: