Interface DataFetchingEnvironment
-
- All Superinterfaces:
IntrospectionDataFetchingEnvironment
- All Known Implementing Classes:
DataFetchingEnvironmentImpl
,DelegatingDataFetchingEnvironment
@PublicApi public interface DataFetchingEnvironment extends IntrospectionDataFetchingEnvironment
A DataFetchingEnvironment instance of passed to aDataFetcher
as a execution context and its the place where you can find out information to help you resolve a data value given a graphql field input
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description boolean
containsArgument(java.lang.String name)
Returns true of the named argument is present<T> T
getArgument(java.lang.String name)
Returns the named argument<T> T
getArgumentOrDefault(java.lang.String name, T defaultValue)
Returns the named argument or the default valuejava.util.Map<java.lang.String,java.lang.Object>
getArguments()
<T> T
getContext()
Deprecated.- usegetGraphQlContext()
instead<K,V>
@Nullable org.dataloader.DataLoader<K,V>getDataLoader(java.lang.String dataLoaderName)
This allows you to retrieve a named dataloader from the underlyingDataLoaderRegistry
org.dataloader.DataLoaderRegistry
getDataLoaderRegistry()
Document
getDocument()
ExecutionId
getExecutionId()
ExecutionStepInfo
getExecutionStepInfo()
Field
getField()
GraphQLFieldDefinition
getFieldDefinition()
java.util.List<Field>
getFields()
Deprecated.UsegetMergedField()
.GraphQLOutputType
getFieldType()
java.util.Map<java.lang.String,FragmentDefinition>
getFragmentsByName()
@NotNull GraphQLContext
getGraphQlContext()
Returns a shared context argument that is set up when theGraphQL.execute(graphql.ExecutionInput)
)} method is invoked.GraphQLSchema
getGraphQLSchema()
<T> T
getLocalContext()
This returns a context object that parent fields may have returned viaDataFetcherResult.getLocalContext()
which can be used to pass down extra information to fields beyond the normalgetSource()
java.util.Locale
getLocale()
MergedField
getMergedField()
It can happen that a query has overlapping fields which are querying the same data.OperationDefinition
getOperationDefinition()
GraphQLType
getParentType()
QueryDirectives
getQueryDirectives()
This gives you access to the directives related to this field<T> T
getRoot()
This is the source object for the root query.DataFetchingFieldSelectionSet
getSelectionSet()
<T> T
getSource()
This is the value of the current object to be queried.java.util.Map<java.lang.String,java.lang.Object>
getVariables()
This returns the variables that have been passed into the query.
-
-
-
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 interfaceIntrospectionDataFetchingEnvironment
- Type Parameters:
T
- you decide what type it is- Returns:
- can be null for the root query, otherwise it is never null
-
getArguments
java.util.Map<java.lang.String,java.lang.Object> getArguments()
- Specified by:
getArguments
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the arguments that have been passed in via the graphql query
-
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 interfaceIntrospectionDataFetchingEnvironment
- 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 argumentdefaultValue
- 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.- usegetGraphQlContext()
insteadReturns a legacy context argument that is set up when theGraphQL.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 theGraphQL.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 viaDataFetcherResult.getLocalContext()
which can be used to pass down extra information to fields beyond the normalgetSource()
This differs from
getGraphQlContext()
in that it's field specific and passed from parent field to child field, whilstgetGraphQlContext()
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.UsegetMergedField()
.- 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
-
getExecutionStepInfo
ExecutionStepInfo getExecutionStepInfo()
- Returns:
- the field
ExecutionStepInfo
for the current data fetch operation
-
getParentType
GraphQLType getParentType()
- Specified by:
getParentType
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the type of the parent of the current field
-
getGraphQLSchema
GraphQLSchema getGraphQLSchema()
- Specified by:
getGraphQLSchema
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the underlying graphql schema
-
getFragmentsByName
java.util.Map<java.lang.String,FragmentDefinition> getFragmentsByName()
- Returns:
- the
FragmentDefinition
map for the current data fetch operation
-
getExecutionId
ExecutionId getExecutionId()
- Returns:
- the
ExecutionId
for the current data fetch operation
-
getSelectionSet
DataFetchingFieldSelectionSet getSelectionSet()
- Returns:
- the
DataFetchingFieldSelectionSet
for the current data fetch operation
-
getQueryDirectives
QueryDirectives getQueryDirectives()
This gives you access to the directives related to this field- Returns:
- the
QueryDirectives
for the currently executing field - See Also:
for more information
-
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 underlyingDataLoaderRegistry
- Type Parameters:
K
- the key typeV
- 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 viagetArguments()
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
-
-