Skip to content

Ability to get parsed directive argument values inside a DataFetcher #1228

@kaqqao

Description

@kaqqao

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");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions