Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix field index computation for Source parameters #1945

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading