Skip to content

PropertyDataFetcher methods can receive an DataFetchingEnvironment object - #1169

Merged
bbakerman merged 9 commits into
graphql-java:masterfrom
bbakerman:1166-allow-method-invocation-with-dfenv
Aug 20, 2018
Merged

bbakerman merged 9 commits into
graphql-java:masterfrom
bbakerman:1166-allow-method-invocation-with-dfenv

Conversation

@bbakerman

@bbakerman bbakerman commented Aug 10, 2018 •

Copy link
Copy Markdown
Member

See #1166

This adds the ability for a getter method to receive the DataFetchingEnvironment as a parameter if it declares it.

It is preferred over a simple getter when 2 are declared

This allows for less boiler plate in your graphql wiring. There is no need to wire in a specific data fetcher for a field because a getter on the source object can take the DataFetchingEnvironment to make specific choices instead.

@bbakerman
bbakerman requested a review from andimarek August 10, 2018 18:32
@bbakerman bbakerman changed the title PropertyDataFetcher methods can receive on DataFetchingEnvironment PropertyDataFetcher methods can receive an DataFetchingEnvironment object Aug 11, 2018
Comment thread docs/data_fetching.rst Outdated
launchDate(dateFormat : String = "dd, MMM, yyyy') : String
}

The ``Query.products`` field ihas a data fetcher, as does each field in the type ``Product``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ihas

Comment thread docs/data_fetching.rst Outdated
Every data fetcher is passed a ``graphql.schema.DataFetchingEnvironment`` object which allows it to know more about what is being fetched
and what arguments have been provided. Here are some of the more interesting parts of ``DataFetchingEnvironment``.

* ``<T> T getSource()`` - the ``source`` object is used to get information for a field. In the simple case its the in memory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source has always been a bit confusing name imho: I often try to describe it as the result of the parent field DF. Not sure this makes it clear, but it is technically correct.

@bbakerman
bbakerman merged commit f02ee24 into graphql-java:master Aug 20, 2018
@andimarek andimarek added this to the 10.0 milestone Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants