Given a query such as:
{
books(author: "John Doe") @cache(enabled = true) {
isbn
title
}
}
where @cache is a custom directive, I'd expect to be able to get the value (true) of the enabled argument in a fashion similar to how I can get the value of author.
Currently, it's only possible to get the non-parsed value:
Value cacheEnabled = dataFetchingEnvironment
.getField()
.getDirective("cache")
.getArgument("enabled")
.getValue()
For a scalar value (like here), it's not too hard to get the parsed value from Value, but it also means taking variables into account. Gets significantly more complicated for object values.
The only way to parse the values is by using ValuesResolver which is internal API.
So I propose an extension to the DataFetchingEnvironment, e.g. DataFetchingEnvironment#getDirectiveArguments(String) that would return the parsed values exactly the same DataFetchingEnvironment#getArguments does:
Map<String, Object> cacheEnabled = dataFetchingEnvironment.getDirectiveArguments("cache");
//or
Optional<Boolean> cacheEnabled = dataFetchingEnvironment
.getDirectiveArgument("cache", "enabled");
Given a query such as:
{ books(author: "John Doe") @cache(enabled = true) { isbn title } }where
@cacheis a custom directive, I'd expect to be able to get the value (true) of theenabledargument in a fashion similar to how I can get the value ofauthor.Currently, it's only possible to get the non-parsed value:
For a scalar value (like here), it's not too hard to get the parsed value from
Value, but it also means taking variables into account. Gets significantly more complicated for object values.The only way to parse the values is by using
ValuesResolverwhich is internal API.So I propose an extension to the
DataFetchingEnvironment, e.g.DataFetchingEnvironment#getDirectiveArguments(String)that would return the parsed values exactly the sameDataFetchingEnvironment#getArgumentsdoes: