Allow non-scalar directive arguments and variables #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The approach of copying the directive args from the document to the args object passed to the resolver (
args[arg.name.value] = arg.value.value;
) only works for scalar argument types, because in the case of aListValueNode
the prop is calledvalues
, for anObjectValueNode
it isfields
, etc., and we would have to descend further into the document to gather the whole structure of the arguments in these cases.graphql-js
exports a helper functiongetDirectiveValues
for exactly this purpose. Using this instead makes it possible for directives to accept arbitrary arguments. I also needed to rewriteparseSchemaDirectives
to build theDirectiveDefinitionNode
s directly from the user-provided directive configuration, because the existing implementation had some baked-in assumptions about there being a single string argument to the directive.