-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ExecutionStepInfoFactory.java
54 lines (43 loc) · 2.31 KB
/
ExecutionStepInfoFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package graphql.execution;
import graphql.Internal;
import graphql.introspection.Introspection;
import graphql.language.Argument;
import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLOutputType;
import graphql.util.FpKit;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
@Internal
public class ExecutionStepInfoFactory {
ValuesResolver valuesResolver = new ValuesResolver();
public ExecutionStepInfo newExecutionStepInfoForSubField(ExecutionContext executionContext, MergedField mergedField, ExecutionStepInfo parentInfo) {
GraphQLObjectType parentType = (GraphQLObjectType) parentInfo.getUnwrappedNonNullType();
GraphQLFieldDefinition fieldDefinition = Introspection.getFieldDef(executionContext.getGraphQLSchema(), parentType, mergedField.getName());
GraphQLOutputType fieldType = fieldDefinition.getType();
List<Argument> fieldArgs = mergedField.getArguments();
GraphQLCodeRegistry codeRegistry = executionContext.getGraphQLSchema().getCodeRegistry();
Supplier<Map<String, Object>> argumentValues = FpKit.intraThreadMemoize(() -> valuesResolver.getArgumentValues(codeRegistry, fieldDefinition.getArguments(), fieldArgs, executionContext.getCoercedVariables()));
ResultPath newPath = parentInfo.getPath().segment(mergedField.getResultKey());
return parentInfo.transform(builder -> builder
.parentInfo(parentInfo)
.type(fieldType)
.fieldDefinition(fieldDefinition)
.fieldContainer(parentType)
.field(mergedField)
.path(newPath)
.arguments(argumentValues));
}
public ExecutionStepInfo newExecutionStepInfoForListElement(ExecutionStepInfo executionInfo, int index) {
GraphQLList fieldType = (GraphQLList) executionInfo.getUnwrappedNonNullType();
GraphQLOutputType typeInList = (GraphQLOutputType) fieldType.getWrappedType();
ResultPath indexedPath = executionInfo.getPath().segment(index);
return executionInfo.transform(builder -> builder
.parentInfo(executionInfo)
.type(typeInList)
.path(indexedPath));
}
}