Package graphql.schema
Class SingletonPropertyDataFetcher<T>
java.lang.Object
graphql.schema.SingletonPropertyDataFetcher<T>
- Type Parameters:
T
- for two
- All Implemented Interfaces:
DataFetcher<T>
,LightDataFetcher<T>
,TrivialDataFetcher<T>
The
SingletonPropertyDataFetcher
is much like the PropertyDataFetcher
except
that it is designed to only ever fetch properties via the name of the field passed in.
This uses the same code as PropertyDataFetcher
and hence is also controlled
by static methods such as PropertyDataFetcher.setUseNegativeCache(boolean)
-
Method Summary
Modifier and TypeMethodDescriptionget
(DataFetchingEnvironment environment) This is called by the graphql engine to fetch the value.get
(GraphQLFieldDefinition fieldDefinition, Object sourceObject, Supplier<DataFetchingEnvironment> environmentSupplier) This is called to by the engine to get a value from the source object in a lightweight fashion.static LightDataFetcher
<?> This returns the same singletonLightDataFetcher
that fetches property values based on the name of the field that iis passed into it.static DataFetcherFactory
<?> This returns the same singletonDataFetcherFactory
that returns the value ofsingleton()
-
Method Details
-
singleton
This returns the same singletonLightDataFetcher
that fetches property values based on the name of the field that iis passed into it.- Returns:
- a singleton property data fetcher
-
singletonFactory
This returns the same singletonDataFetcherFactory
that returns the value ofsingleton()
- Returns:
- a singleton data fetcher factory
-
get
public T get(GraphQLFieldDefinition fieldDefinition, Object sourceObject, Supplier<DataFetchingEnvironment> environmentSupplier) throws Exception Description copied from interface:LightDataFetcher
This is called to by the engine to get a value from the source object in a lightweight fashion. Only the field and source object are passed in a materialised way. The more heavy weightDataFetchingEnvironment
is wrapped in a supplier that is only created on demand.If you are a lightweight data fetcher (like
PropertyDataFetcher
is) then you can implement this method to have a more lightweight method invocation. However, if you need field arguments etc. during fetching (most custom fetchers will) then you should use implementDataFetcher.get(DataFetchingEnvironment)
.- Specified by:
get
in interfaceLightDataFetcher<T>
- Parameters:
fieldDefinition
- the graphql field definitionsourceObject
- the source object to get a value fromenvironmentSupplier
- a supplier of theDataFetchingEnvironment
that creates it lazily- Returns:
- a value of type T. May be wrapped in a
DataFetcherResult
- Throws:
Exception
- to relieve the implementations from having to wrap checked exceptions. Any exception thrown from aDataFetcher
will eventually be handled by the registeredDataFetcherExceptionHandler
and the related field will have a value ofnull
in the result.
-
get
Description copied from interface:DataFetcher
This is called by the graphql engine to fetch the value. TheDataFetchingEnvironment
is a composite context object that tells you all you need to know about how to fetch a data value in graphql type terms.- Specified by:
get
in interfaceDataFetcher<T>
- Parameters:
environment
- this is the data fetching environment which contains all the context you need to fetch a value- Returns:
- a value of type T. May be wrapped in a
DataFetcherResult
- Throws:
Exception
- to relieve the implementations from having to wrap checked exceptions. Any exception thrown from aDataFetcher
will eventually be handled by the registeredDataFetcherExceptionHandler
and the related field will have a value ofnull
in the result.
-