|
23 | 23 |
|
24 | 24 | import java.util.HashMap;
|
25 | 25 | import java.util.Optional;
|
26 |
| -import java.util.concurrent.CompletableFuture; |
27 | 26 |
|
28 | 27 | public class EnhancedExecutionStrategy extends AsyncSerialExecutionStrategy {
|
29 | 28 |
|
30 | 29 | private static final String CLIENT_MUTATION_ID = "clientMutationId";
|
31 | 30 |
|
32 | 31 | @Override
|
33 |
| - protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { |
| 32 | + protected Object resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { |
34 | 33 | GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType();
|
35 | 34 | GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, parameters.getField().getSingleField());
|
36 | 35 | if (fieldDef == null) return null;
|
37 | 36 |
|
38 |
| - if (fieldDef.getName().contentEquals(CLIENT_MUTATION_ID)) { |
| 37 | + return super.resolveField(executionContext, parameters); |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException { |
| 42 | + graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType(); |
| 43 | + |
| 44 | + if (parameters.getExecutionStepInfo().getFieldDefinition().getName().contentEquals(CLIENT_MUTATION_ID)) { |
39 | 45 | Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0);
|
40 | 46 | Argument argument = field.getArguments().get(0);
|
41 | 47 |
|
42 | 48 | Object clientMutationId;
|
43 | 49 | if (argument.getValue() instanceof VariableReference) {
|
44 | 50 | VariableReference ref = (VariableReference) argument.getValue();
|
45 |
| - HashMap mutationInputVariables = (HashMap) executionContext.getVariables().get(ref.getName()); |
| 51 | + HashMap mutationInputVariables = (HashMap) executionContext.getCoercedVariables().get(ref.getName()); |
46 | 52 | clientMutationId = mutationInputVariables.get(CLIENT_MUTATION_ID);
|
47 | 53 | } else {
|
48 | 54 | ObjectValue value = (ObjectValue) field.getArguments().get(0).getValue();
|
49 | 55 | StringValue clientMutationIdVal = (StringValue) value.getObjectFields().stream()
|
50 |
| - .filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID)) |
51 |
| - .findFirst().get().getValue(); |
| 56 | + .filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID)) |
| 57 | + .findFirst().get().getValue(); |
52 | 58 | clientMutationId = clientMutationIdVal.getValue();
|
53 | 59 | }
|
54 |
| - |
55 |
| - ExecutionStepInfo fieldTypeInfo = ExecutionStepInfo.newExecutionStepInfo().type(fieldDef.getType()).parentInfo(parameters.getExecutionStepInfo()).build(); |
56 |
| - ExecutionStrategyParameters newParameters = ExecutionStrategyParameters.newParameters() |
57 |
| - .fields(parameters.getFields()) |
58 |
| - .nonNullFieldValidator(parameters.getNonNullFieldValidator()) |
59 |
| - .executionStepInfo(fieldTypeInfo) |
60 |
| - .source(clientMutationId) |
61 |
| - .build(); |
62 |
| - |
63 |
| - |
64 |
| - return completeValue(executionContext, newParameters).getFieldValue(); |
65 |
| - } else { |
66 |
| - return super.resolveField(executionContext, parameters); |
| 60 | + return super.completeValue(executionContext, withSource(parameters, clientMutationId)); |
67 | 61 | }
|
68 |
| - } |
69 | 62 |
|
70 |
| - @Override |
71 |
| - protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException { |
72 |
| - graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType(); |
73 | 63 | Object result = parameters.getSource();
|
74 | 64 | if (result instanceof Enum && fieldType instanceof GraphQLEnumType) {
|
75 | 65 | Object value = ((GraphQLEnumType) fieldType).parseValue(((Enum) result).name());
|
|
0 commit comments