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 classDataFetchingEnvironmentImpl.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsArgument(java.lang.String name)Returns true of the named argument is present<T> TgetArgument(java.lang.String name)Returns the named argument<T> TgetArgumentOrDefault(java.lang.String name, T defaultValue)Returns the named argument or the default valuejava.util.Map<java.lang.String,java.lang.Object>getArguments()<T> TgetContext()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 underlyingDataLoaderRegistryorg.dataloader.DataLoaderRegistrygetDataLoaderRegistry()DocumentgetDocument()ExecutionIdgetExecutionId()ExecutionStepInfogetExecutionStepInfo()FieldgetField()GraphQLFieldDefinitiongetFieldDefinition()java.util.List<Field>getFields()GraphQLOutputTypegetFieldType()java.util.Map<java.lang.String,FragmentDefinition>getFragmentsByName()@NotNull GraphQLContextgetGraphQlContext()Returns a shared context argument that is set up when theGraphQL.execute(graphql.ExecutionInput))} method is invoked.GraphQLSchemagetGraphQLSchema()<T> TgetLocalContext()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.LocalegetLocale()MergedFieldgetMergedField()It can happen that a query has overlapping fields which are querying the same data.OperationDefinitiongetOperationDefinition()GraphQLTypegetParentType()QueryDirectivesgetQueryDirectives()This gives you access to the directives related to this field<T> TgetRoot()This is the source object for the root query.DataFetchingFieldSelectionSetgetSelectionSet()<T> TgetSource()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.BuildernewDataFetchingEnvironment()static DataFetchingEnvironmentImpl.BuildernewDataFetchingEnvironment(ExecutionContext executionContext)static DataFetchingEnvironmentImpl.BuildernewDataFetchingEnvironment(DataFetchingEnvironment environment)java.lang.StringtoString()
-
-
-
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:DataFetchingEnvironmentThis 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:
getSourcein interfaceDataFetchingEnvironment- Specified by:
getSourcein 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:
getArgumentsin interfaceDataFetchingEnvironment- Specified by:
getArgumentsin 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:DataFetchingEnvironmentReturns true of the named argument is present- Specified by:
containsArgumentin 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:DataFetchingEnvironmentReturns the named argument- Specified by:
getArgumentin interfaceDataFetchingEnvironment- Specified by:
getArgumentin 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:DataFetchingEnvironmentReturns the named argument or the default value- Specified by:
getArgumentOrDefaultin 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:DataFetchingEnvironmentReturns 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:
getContextin interfaceDataFetchingEnvironment- Type Parameters:
T- you decide what type it is- Returns:
- can be null
-
getGraphQlContext
@NotNull public @NotNull GraphQLContext getGraphQlContext()
Description copied from interface:DataFetchingEnvironmentReturns 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:
getGraphQlContextin interfaceDataFetchingEnvironment- Returns:
- can NOT be null
-
getLocalContext
@Nullable public <T> T getLocalContext()
Description copied from interface:DataFetchingEnvironmentThis 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:
getLocalContextin 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:DataFetchingEnvironmentThis is the source object for the root query.- Specified by:
getRootin interfaceDataFetchingEnvironment- Type Parameters:
T- you decide what type it is- Returns:
- can be null
-
getFieldDefinition
public GraphQLFieldDefinition getFieldDefinition()
- Specified by:
getFieldDefinitionin interfaceDataFetchingEnvironment- Returns:
- the definition of the current field
-
getFields
public java.util.List<Field> getFields()
- Specified by:
getFieldsin interfaceDataFetchingEnvironment- Returns:
- the list of fields
-
getField
public Field getField()
- Specified by:
getFieldin interfaceDataFetchingEnvironment- Returns:
- returns the field which is currently queried. See also
DataFetchingEnvironment.getMergedField().
-
getMergedField
public MergedField getMergedField()
Description copied from interface:DataFetchingEnvironmentIt 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:
getMergedFieldin interfaceDataFetchingEnvironment- Returns:
- the list of fields currently queried
-
getFieldType
public GraphQLOutputType getFieldType()
- Specified by:
getFieldTypein interfaceDataFetchingEnvironment- Returns:
- graphql type of the current field
-
getParentType
public GraphQLType getParentType()
- Specified by:
getParentTypein interfaceDataFetchingEnvironment- Specified by:
getParentTypein interfaceIntrospectionDataFetchingEnvironment- Returns:
- the type of the parent of the current field
-
getGraphQLSchema
public GraphQLSchema getGraphQLSchema()
- Specified by:
getGraphQLSchemain interfaceDataFetchingEnvironment- Specified by:
getGraphQLSchemain interfaceIntrospectionDataFetchingEnvironment- Returns:
- the underlying graphql schema
-
getFragmentsByName
public java.util.Map<java.lang.String,FragmentDefinition> getFragmentsByName()
- Specified by:
getFragmentsByNamein interfaceDataFetchingEnvironment- Returns:
- the
FragmentDefinitionmap for the current data fetch operation
-
getExecutionId
public ExecutionId getExecutionId()
- Specified by:
getExecutionIdin interfaceDataFetchingEnvironment- Returns:
- the
ExecutionIdfor the current data fetch operation
-
getSelectionSet
public DataFetchingFieldSelectionSet getSelectionSet()
- Specified by:
getSelectionSetin interfaceDataFetchingEnvironment- Returns:
- the
DataFetchingFieldSelectionSetfor the current data fetch operation
-
getQueryDirectives
public QueryDirectives getQueryDirectives()
Description copied from interface:DataFetchingEnvironmentThis gives you access to the directives related to this field- Specified by:
getQueryDirectivesin interfaceDataFetchingEnvironment- Returns:
- the
QueryDirectivesfor the currently executing field - See Also:
for more information
-
getExecutionStepInfo
public ExecutionStepInfo getExecutionStepInfo()
- Specified by:
getExecutionStepInfoin interfaceDataFetchingEnvironment- Returns:
- the field
ExecutionStepInfofor 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:DataFetchingEnvironmentThis allows you to retrieve a named dataloader from the underlyingDataLoaderRegistry- Specified by:
getDataLoaderin 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:
getDataLoaderRegistryin interfaceDataFetchingEnvironment- Returns:
- the
DataLoaderRegistryin play
-
getLocale
public java.util.Locale getLocale()
- Specified by:
getLocalein interfaceDataFetchingEnvironment- Returns:
- the current
Localeinstance used for this request
-
getOperationDefinition
public OperationDefinition getOperationDefinition()
- Specified by:
getOperationDefinitionin interfaceDataFetchingEnvironment- Returns:
- the current operation that is being executed
-
getDocument
public Document getDocument()
- Specified by:
getDocumentin 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:DataFetchingEnvironmentThis 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:
getVariablesin interfaceDataFetchingEnvironment- Returns:
- the coerced variables that have been passed to the query that is being executed
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-