Skip to content

Commit

Permalink
Merge pull request #1945 from dpolysiou/main-issue-36658
Browse files Browse the repository at this point in the history
Fix field index computation for Source parameters
  • Loading branch information
phillip-kruger authored Oct 24, 2023
2 parents 23f2113 + d280d10 commit b9e489d
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Path;

import org.eclipse.microprofile.graphql.Source;

import graphql.execution.DataFetcherResult;
import graphql.language.Argument;
import graphql.language.Field;
Expand Down Expand Up @@ -73,12 +75,15 @@ private Argument requestedArgument(Path.Node node) {
private int parameterIndex(String name) {
Parameter[] parameters = method.getParameters();
int index = 0;
for (int i = 0; i < parameters.length; i++) {
if (name.equals(parameters[i].getName())) {
for (Parameter parameter : parameters) {
if (name.equals(parameter.getName())) {
return index;
}
// parameters of type Context are not stored as arguments in the FieldDefinition, so don't increment the index on them
if (!parameters[i].getType().isAssignableFrom(Context.class)) {
boolean isContext = parameter.getType().isAssignableFrom(Context.class);
// similarly, parameters annotated with @Source are also not stored as arguments in the FieldDefinition
boolean isAnnotatedWithSource = parameter.getAnnotation(Source.class) != null;
if (!isContext && !isAnnotatedWithSource) {
index++;
}
}
Expand Down

0 comments on commit b9e489d

Please sign in to comment.