graphql.execution.ConditionalNodes Maven / Gradle / Ivy
package graphql.execution;
import graphql.language.Directive;
import java.util.List;
import java.util.Map;
import static graphql.Directives.IncludeDirective;
import static graphql.Directives.SkipDirective;
public class ConditionalNodes {
ValuesResolver valuesResolver;
public ConditionalNodes() {
valuesResolver = new ValuesResolver();
}
public boolean shouldInclude(ExecutionContext executionContext, List directives) {
Directive skipDirective = findDirective(directives, SkipDirective.getName());
if (skipDirective != null) {
Map argumentValues = valuesResolver.getArgumentValues(SkipDirective.getArguments(), skipDirective.getArguments(), executionContext.getVariables());
return !(Boolean) argumentValues.get("if");
}
Directive includeDirective = findDirective(directives, IncludeDirective.getName());
if (includeDirective != null) {
Map argumentValues = valuesResolver.getArgumentValues(IncludeDirective.getArguments(), includeDirective.getArguments(), executionContext.getVariables());
return (Boolean) argumentValues.get("if");
}
return true;
}
private Directive findDirective(List directives, String name) {
for (Directive directive : directives) {
if (directive.getName().equals(name)) return directive;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy