Class SingletonPropertyDataFetcher<T>

    • Method Detail

      • singleton

        public static LightDataFetcher<?> singleton()
        This returns the same singleton LightDataFetcher that fetches property values based on the name of the field that iis passed into it.
        Returns:
        a singleton property data fetcher
      • get

        public T get​(GraphQLFieldDefinition fieldDefinition,
                     java.lang.Object sourceObject,
                     java.util.function.Supplier<DataFetchingEnvironment> environmentSupplier)
              throws java.lang.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 weight DataFetchingEnvironment 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 implement DataFetcher.get(DataFetchingEnvironment).

        Specified by:
        get in interface LightDataFetcher<T>
        Parameters:
        fieldDefinition - the graphql field definition
        sourceObject - the source object to get a value from
        environmentSupplier - a supplier of the DataFetchingEnvironment that creates it lazily
        Returns:
        a value of type T. May be wrapped in a DataFetcherResult
        Throws:
        java.lang.Exception - to relieve the implementations from having to wrap checked exceptions. Any exception thrown from a DataFetcher will eventually be handled by the registered DataFetcherExceptionHandler and the related field will have a value of null in the result.
      • get

        public T get​(DataFetchingEnvironment environment)
              throws java.lang.Exception
        Description copied from interface: DataFetcher
        This is called by the graphql engine to fetch the value. The DataFetchingEnvironment 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 interface DataFetcher<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:
        java.lang.Exception - to relieve the implementations from having to wrap checked exceptions. Any exception thrown from a DataFetcher will eventually be handled by the registered DataFetcherExceptionHandler and the related field will have a value of null in the result.