|
24 | 24 | import org.slf4j.Logger; |
25 | 25 | import org.slf4j.LoggerFactory; |
26 | 26 |
|
| 27 | +import java.util.HashMap; |
27 | 28 | import java.util.List; |
28 | | -import java.util.Map; |
29 | 29 | import java.util.Optional; |
30 | 30 |
|
31 | 31 | public class EnhancedExecutionStrategy extends SimpleExecutionStrategy { |
32 | 32 |
|
33 | 33 | private static final Logger log = LoggerFactory.getLogger(EnhancedExecutionStrategy.class); |
| 34 | + private static final String CLIENT_MUTATION_ID = "clientMutationId"; |
34 | 35 |
|
35 | 36 | @Override |
36 | 37 | protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, List<Field> fields) { |
37 | 38 | GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0)); |
38 | 39 | if (fieldDef == null) return null; |
39 | 40 |
|
40 | | - if (fieldDef.getName().contentEquals("clientMutationId")) { |
| 41 | + if (fieldDef.getName().contentEquals(CLIENT_MUTATION_ID)) { |
41 | 42 | Field field = (Field) executionContext.getOperationDefinition().getSelectionSet().getSelections().get(0); |
42 | | - ObjectValue value = (ObjectValue) field.getArguments().get(0).getValue(); |
43 | | - StringValue clientMutationIdVal = (StringValue) value.getObjectFields().stream().filter(f -> f.getName().contentEquals("clientMutationId")).findFirst().get().getValue(); |
| 43 | + Argument argument = field.getArguments().get(0); |
44 | 44 |
|
45 | | - String clientMutationId = clientMutationIdVal.getValue(); |
| 45 | + Object clientMutationId; |
| 46 | + if (argument.getValue() instanceof VariableReference) { |
| 47 | + VariableReference ref = (VariableReference) argument.getValue(); |
| 48 | + HashMap mutationInputVariables = (HashMap) executionContext.getVariables().get(ref.getName()); |
| 49 | + clientMutationId = mutationInputVariables.get(CLIENT_MUTATION_ID); |
| 50 | + } else { |
| 51 | + ObjectValue value = (ObjectValue) field.getArguments().get(0).getValue(); |
| 52 | + StringValue clientMutationIdVal = (StringValue) value.getObjectFields().stream() |
| 53 | + .filter(f -> f.getName().contentEquals(CLIENT_MUTATION_ID)) |
| 54 | + .findFirst().get().getValue(); |
| 55 | + clientMutationId = clientMutationIdVal.getValue(); |
| 56 | + } |
46 | 57 |
|
47 | 58 | return completeValue(executionContext, fieldDef.getType(), fields, clientMutationId); |
48 | 59 | } else { |
|
0 commit comments