Class DataFetchingEnvironmentImpl
- java.lang.Object
-
- graphql.schema.DataFetchingEnvironmentImpl
-
- All Implemented Interfaces:
IntrospectionDataFetchingEnvironment
,DataFetchingEnvironment
public class DataFetchingEnvironmentImpl extends java.lang.Object implements DataFetchingEnvironment
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataFetchingEnvironmentImpl.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete 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()
Returns a legacy context argument that is set up when theGraphQL.execute(graphql.ExecutionInput)
method is invoked.<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()
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 normalDataFetchingEnvironment.getSource()
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.static DataFetchingEnvironmentImpl.Builder
newDataFetchingEnvironment()
static DataFetchingEnvironmentImpl.Builder
newDataFetchingEnvironment(ExecutionContext executionContext)
static DataFetchingEnvironmentImpl.Builder
newDataFetchingEnvironment(DataFetchingEnvironment environment)
java.lang.String
toString()
-
-
-
Method Detail
-
newDataFetchingEnvironment
public static DataFetchingEnvironmentImpl.Builder newDataFetchingEnvironment()
- Returns:
- a new
DataFetchingEnvironmentImpl.Builder
-
newDataFetchingEnvironment
public static DataFetchingEnvironmentImpl.Builder newDataFetchingEnvironment(DataFetchingEnvironment environment)
-
newDataFetchingEnvironment
public static DataFetchingEnvironmentImpl.Builder newDataFetchingEnvironment(ExecutionContext executionContext)
-
getSource
public <T> T getSource()
Description copied from interface:DataFetchingEnvironment
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 {
DataFetchingEnvironment.getRoot()
- Specified by:
getSource
in interfaceDataFetchingEnvironment
- 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
public java.util.Map<java.lang.String,java.lang.Object> getArguments()
- Specified by:
getArguments
in interfaceDataFetchingEnvironment
- Specified by:
getArguments
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the arguments that have been passed in via the graphql query
-
containsArgument
public boolean containsArgument(java.lang.String name)
Description copied from interface:DataFetchingEnvironment
Returns true of the named argument is present- Specified by:
containsArgument
in interfaceDataFetchingEnvironment
- Parameters:
name
- the name of the argument- Returns:
- true of the named argument is present
-
getArgument
public <T> T getArgument(java.lang.String name)
Description copied from interface:DataFetchingEnvironment
Returns the named argument- Specified by:
getArgument
in interfaceDataFetchingEnvironment
- 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
public <T> T getArgumentOrDefault(java.lang.String name, T defaultValue)
Description copied from interface:DataFetchingEnvironment
Returns the named argument or the default value- Specified by:
getArgumentOrDefault
in interfaceDataFetchingEnvironment
- 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
public <T> T getContext()
Description copied from interface:DataFetchingEnvironment
Returns 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.
- Specified by:
getContext
in interfaceDataFetchingEnvironment
- Type Parameters:
T
- you decide what type it is- Returns:
- can be null
-
getGraphQlContext
@NotNull public @NotNull GraphQLContext getGraphQlContext()
Description copied from interface:DataFetchingEnvironment
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.
- Specified by:
getGraphQlContext
in interfaceDataFetchingEnvironment
- Returns:
- can NOT be null
-
getLocalContext
@Nullable public <T> T getLocalContext()
Description copied from interface:DataFetchingEnvironment
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 normalDataFetchingEnvironment.getSource()
This differs from
DataFetchingEnvironment.getGraphQlContext()
in that it's field specific and passed from parent field to child field, whilstDataFetchingEnvironment.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.
- Specified by:
getLocalContext
in interfaceDataFetchingEnvironment
- 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
public <T> T getRoot()
Description copied from interface:DataFetchingEnvironment
This is the source object for the root query.- Specified by:
getRoot
in interfaceDataFetchingEnvironment
- Type Parameters:
T
- you decide what type it is- Returns:
- can be null
-
getFieldDefinition
public GraphQLFieldDefinition getFieldDefinition()
- Specified by:
getFieldDefinition
in interfaceDataFetchingEnvironment
- Returns:
- the definition of the current field
-
getFields
public java.util.List<Field> getFields()
- Specified by:
getFields
in interfaceDataFetchingEnvironment
- Returns:
- the list of fields
-
getField
public Field getField()
- Specified by:
getField
in interfaceDataFetchingEnvironment
- Returns:
- returns the field which is currently queried. See also
DataFetchingEnvironment.getMergedField()
.
-
getMergedField
public MergedField getMergedField()
Description copied from interface:DataFetchingEnvironment
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
DataFetchingEnvironment.getField()
.Example query with more than one Field returned:
query Foo { bar ...BarFragment } fragment BarFragment on Query { bar }
- Specified by:
getMergedField
in interfaceDataFetchingEnvironment
- Returns:
- the list of fields currently queried
-
getFieldType
public GraphQLOutputType getFieldType()
- Specified by:
getFieldType
in interfaceDataFetchingEnvironment
- Returns:
- graphql type of the current field
-
getParentType
public GraphQLType getParentType()
- Specified by:
getParentType
in interfaceDataFetchingEnvironment
- Specified by:
getParentType
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the type of the parent of the current field
-
getGraphQLSchema
public GraphQLSchema getGraphQLSchema()
- Specified by:
getGraphQLSchema
in interfaceDataFetchingEnvironment
- Specified by:
getGraphQLSchema
in interfaceIntrospectionDataFetchingEnvironment
- Returns:
- the underlying graphql schema
-
getFragmentsByName
public java.util.Map<java.lang.String,FragmentDefinition> getFragmentsByName()
- Specified by:
getFragmentsByName
in interfaceDataFetchingEnvironment
- Returns:
- the
FragmentDefinition
map for the current data fetch operation
-
getExecutionId
public ExecutionId getExecutionId()
- Specified by:
getExecutionId
in interfaceDataFetchingEnvironment
- Returns:
- the
ExecutionId
for the current data fetch operation
-
getSelectionSet
public DataFetchingFieldSelectionSet getSelectionSet()
- Specified by:
getSelectionSet
in interfaceDataFetchingEnvironment
- Returns:
- the
DataFetchingFieldSelectionSet
for the current data fetch operation
-
getQueryDirectives
public QueryDirectives getQueryDirectives()
Description copied from interface:DataFetchingEnvironment
This gives you access to the directives related to this field- Specified by:
getQueryDirectives
in interfaceDataFetchingEnvironment
- Returns:
- the
QueryDirectives
for the currently executing field - See Also:
for more information
-
getExecutionStepInfo
public ExecutionStepInfo getExecutionStepInfo()
- Specified by:
getExecutionStepInfo
in interfaceDataFetchingEnvironment
- Returns:
- the field
ExecutionStepInfo
for the current data fetch operation
-
getDataLoader
@Nullable public <K,V> @Nullable org.dataloader.DataLoader<K,V> getDataLoader(java.lang.String dataLoaderName)
Description copied from interface:DataFetchingEnvironment
This allows you to retrieve a named dataloader from the underlyingDataLoaderRegistry
- Specified by:
getDataLoader
in interfaceDataFetchingEnvironment
- 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
public org.dataloader.DataLoaderRegistry getDataLoaderRegistry()
- Specified by:
getDataLoaderRegistry
in interfaceDataFetchingEnvironment
- Returns:
- the
DataLoaderRegistry
in play
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocale
in interfaceDataFetchingEnvironment
- Returns:
- the current
Locale
instance used for this request
-
getOperationDefinition
public OperationDefinition getOperationDefinition()
- Specified by:
getOperationDefinition
in interfaceDataFetchingEnvironment
- Returns:
- the current operation that is being executed
-
getDocument
public Document getDocument()
- Specified by:
getDocument
in interfaceDataFetchingEnvironment
- Returns:
- the current query Document that is being executed
-
getVariables
public java.util.Map<java.lang.String,java.lang.Object> getVariables()
Description copied from interface:DataFetchingEnvironment
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 viaDataFetchingEnvironment.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.- Specified by:
getVariables
in interfaceDataFetchingEnvironment
- Returns:
- the coerced variables that have been passed to the query that is being executed
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-