|
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) { |
34 | | - GraphQLObjectType parentType = (GraphQLObjectType) parameters.getExecutionStepInfo().getUnwrappedNonNullType(); |
35 | | - GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, parameters.getField().getSingleField()); |
36 | | - if (fieldDef == null) return null; |
| 32 | + protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException { |
| 33 | + graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType(); |
37 | 34 |
|
38 | | - if (fieldDef.getName().contentEquals(CLIENT_MUTATION_ID)) { |
| 35 | + if (parameters.getExecutionStepInfo().getFieldDefinition().getName().contentEquals(CLIENT_MUTATION_ID)) { |
39 | 36 | Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0); |
40 | 37 | Argument argument = field.getArguments().get(0); |
41 | 38 |
|
42 | 39 | Object clientMutationId; |
43 | 40 | if (argument.getValue() instanceof VariableReference) { |
44 | 41 | VariableReference ref = (VariableReference) argument.getValue(); |
45 | | - HashMap mutationInputVariables = (HashMap) executionContext.getVariables().get(ref.getName()); |
| 42 | + HashMap mutationInputVariables = (HashMap) executionContext.getCoercedVariables().get(ref.getName()); |
46 | 43 | clientMutationId = mutationInputVariables.get(CLIENT_MUTATION_ID); |
47 | 44 | } else { |
48 | 45 | ObjectValue value = (ObjectValue) field.getArguments().get(0).getValue(); |
49 | 46 | StringValue clientMutationIdVal = (StringValue) value.getObjectFields().stream() |
50 | | - .filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID)) |
51 | | - .findFirst().get().getValue(); |
| 47 | + .filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID)) |
| 48 | + .findFirst().get().getValue(); |
52 | 49 | clientMutationId = clientMutationIdVal.getValue(); |
53 | 50 | } |
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); |
| 51 | + return super.completeValue(executionContext, withSource(parameters, clientMutationId)); |
67 | 52 | } |
68 | | - } |
69 | 53 |
|
70 | | - @Override |
71 | | - protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException { |
72 | | - graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType(); |
73 | 54 | Object result = parameters.getSource(); |
74 | 55 | if (result instanceof Enum && fieldType instanceof GraphQLEnumType) { |
75 | 56 | Object value = ((GraphQLEnumType) fieldType).parseValue(((Enum) result).name()); |
|
0 commit comments