Skip to content

Commit f39d26f

Browse files
Fixed variable references not being resolved when parsing 'clientMutationId' for Relay Mutations
1 parent 28aeae2 commit f39d26f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/main/java/graphql/annotations/EnhancedExecutionStrategy.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,36 @@
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
2626

27+
import java.util.HashMap;
2728
import java.util.List;
28-
import java.util.Map;
2929
import java.util.Optional;
3030

3131
public class EnhancedExecutionStrategy extends SimpleExecutionStrategy {
3232

3333
private static final Logger log = LoggerFactory.getLogger(EnhancedExecutionStrategy.class);
34+
private static final String CLIENT_MUTATION_ID = "clientMutationId";
3435

3536
@Override
3637
protected ExecutionResult resolveField(ExecutionContext executionContext, GraphQLObjectType parentType, Object source, List<Field> fields) {
3738
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, fields.get(0));
3839
if (fieldDef == null) return null;
3940

40-
if (fieldDef.getName().contentEquals("clientMutationId")) {
41+
if (fieldDef.getName().contentEquals(CLIENT_MUTATION_ID)) {
4142
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);
4444

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+
}
4657

4758
return completeValue(executionContext, fieldDef.getType(), fields, clientMutationId);
4859
} else {

0 commit comments

Comments
 (0)