Interface DataFetchingEnvironment

    • Method Detail

      • getSource

        @Nullable
        <T> T getSource()
        This is the value of the current object to be queried. Or to put it differently: it is the value of the parent field.

        For the root query, it is equal to {getRoot()

        Specified by:
        getSource in interface IntrospectionDataFetchingEnvironment
        Type Parameters:
        T - you decide what type it is
        Returns:
        can be null for the root query, otherwise it is never null
      • containsArgument

        boolean containsArgument​(java.lang.String name)
        Returns true of the named argument is present
        Parameters:
        name - the name of the argument
        Returns:
        true of the named argument is present
      • getArgument

        @Nullable
        <T> T getArgument​(java.lang.String name)
        Returns the named argument
        Specified by:
        getArgument in interface IntrospectionDataFetchingEnvironment
        Type Parameters:
        T - you decide what type it is
        Parameters:
        name - the name of the argument
        Returns:
        the named argument or null if it's not present
      • getArgumentOrDefault

        <T> T getArgumentOrDefault​(java.lang.String name,
                                   T defaultValue)
        Returns the named argument or the default value
        Type Parameters:
        T - you decide what type it is
        Parameters:
        name - the name of the argument
        defaultValue - the default value if the argument is not present
        Returns:
        the named argument or the default if it's not present
      • getContext

        @Deprecated(since="2021-07-05")
        <T> T getContext()
        Deprecated.
        - use getGraphQlContext() instead
        Returns a legacy context argument that is set up when the GraphQL.execute(graphql.ExecutionInput) method is invoked.

        This is an info object which is provided to all DataFetchers, but never used by graphql-java itself.

        Type Parameters:
        T - you decide what type it is
        Returns:
        can be null
      • getGraphQlContext

        @NotNull
        @NotNull GraphQLContext getGraphQlContext()
        Returns a shared context argument that is set up when the GraphQL.execute(graphql.ExecutionInput) )} method is invoked.

        This is an info object which is provided to all DataFetchers.

        Returns:
        can NOT be null
      • getLocalContext

        @Nullable
        <T> T getLocalContext()
        This returns a context object that parent fields may have returned via DataFetcherResult.getLocalContext() which can be used to pass down extra information to fields beyond the normal getSource()

        This differs from getGraphQlContext() in that it's field specific and passed from parent field to child field, whilst getGraphQlContext() is global for the whole query.

        If the field is a top level field then 'localContext' equals null since it's never be set until those fields execute.

        Type Parameters:
        T - you decide what type it is
        Returns:
        can be null if no field context objects are passed back by previous parent fields
      • getRoot

        <T> T getRoot()
        This is the source object for the root query.
        Type Parameters:
        T - you decide what type it is
        Returns:
        can be null
      • getFieldDefinition

        GraphQLFieldDefinition getFieldDefinition()
        Returns:
        the definition of the current field
      • getFields

        @Deprecated(since="2018-12-20")
        java.util.List<Field> getFields()
        Deprecated.
        Returns:
        the list of fields
      • getMergedField

        MergedField getMergedField()
        It can happen that a query has overlapping fields which are querying the same data. If this is the case they get merged together and fetched only once, but this method returns all of the Fields from the query.

        Most of the time you probably want to use getField().

        Example query with more than one Field returned:

         
        
              query Foo {
                  bar
                  ...BarFragment
              }
        
              fragment BarFragment on Query {
                  bar
              }
         
         
        Returns:
        the list of fields currently queried
      • getField

        Field getField()
        Returns:
        returns the field which is currently queried. See also getMergedField().
      • getFieldType

        GraphQLOutputType getFieldType()
        Returns:
        graphql type of the current field
      • getDataLoader

        @Nullable
        <K,​V> @Nullable org.dataloader.DataLoader<K,​V> getDataLoader​(java.lang.String dataLoaderName)
        This allows you to retrieve a named dataloader from the underlying DataLoaderRegistry
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        dataLoaderName - the name of the data loader to fetch
        Returns:
        the named data loader or null
        See Also:
        DataLoaderRegistry.getDataLoader(String)
      • getDataLoaderRegistry

        org.dataloader.DataLoaderRegistry getDataLoaderRegistry()
        Returns:
        the DataLoaderRegistry in play
      • getLocale

        java.util.Locale getLocale()
        Returns:
        the current Locale instance used for this request
      • getOperationDefinition

        OperationDefinition getOperationDefinition()
        Returns:
        the current operation that is being executed
      • getDocument

        Document getDocument()
        Returns:
        the current query Document that is being executed
      • getVariables

        java.util.Map<java.lang.String,​java.lang.Object> getVariables()
        This returns the variables that have been passed into the query. Note that this is the query variables themselves and not the arguments to the field, which is accessed via getArguments()

        The field arguments are created by interpolating any referenced variables and AST literals and resolving them into the arguments.

        Also note that the raw query variables are "coerced" into a map where the leaf scalar and enum types are called to create input coerced values. So the values you get here are not exactly as passed via ExecutionInput.getVariables() but have been processed.

        Returns:
        the coerced variables that have been passed to the query that is being executed