graphql.execution.nextgen.result.ResultNodeAdapter Maven / Gradle / Ivy
package graphql.execution.nextgen.result;
import graphql.PublicApi;
import graphql.util.NodeAdapter;
import graphql.util.NodeLocation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static graphql.Assert.assertNotNull;
import static graphql.Assert.assertTrue;
@PublicApi
public class ResultNodeAdapter implements NodeAdapter {
public static final ResultNodeAdapter RESULT_NODE_ADAPTER = new ResultNodeAdapter();
private ResultNodeAdapter() {
}
@Override
public Map> getNamedChildren(ExecutionResultNode parentNode) {
return Collections.singletonMap(null, parentNode.getChildren());
}
@Override
public ExecutionResultNode withNewChildren(ExecutionResultNode parentNode, Map> newChildren) {
assertTrue(newChildren.size() == 1);
List childrenList = newChildren.get(null);
assertNotNull(childrenList);
return parentNode.withNewChildren(childrenList);
}
@Override
public ExecutionResultNode removeChild(ExecutionResultNode parentNode, NodeLocation location) {
int index = location.getIndex();
List childrenList = new ArrayList<>(parentNode.getChildren());
assertTrue(index >= 0 && index < childrenList.size(), "The remove index MUST be within the range of the children");
childrenList.remove(index);
return parentNode.withNewChildren(childrenList);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy