Skip to content

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

Closed

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

Activity

  1. added a commit that references this issue on Sep 17, 2018
    5198d18
  2. bbakerman commented on Oct 24, 2018

    @bbakerman
    Member

    @kaqqao - this will help any efforts in regard to #1211 - eg better input validation.

  3. added this to the 13.0 milestone on May 3, 2019
  4. modified the milestones: 13.0, 14.0 on Jul 16, 2019
  5. removed this from the 14.0 milestone on Jan 16, 2020
  6. dondonz commented on Nov 17, 2022

    @dondonz
    Member

    Closing this old issue as PRs have been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions