Java Code Examples for graphql.execution.ExecutionPath#toList()
The following examples show how to use
graphql.execution.ExecutionPath#toList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformException.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private List<String> toPathList(ExecutionPath path) { List<String> l = new ArrayList<>(); for (Object o : path.toList()) { l.add(o.toString()); } return l; }
Example 2
Source File: Util.java From samples with MIT License | 5 votes |
public static ExecutionPath concatPaths(ExecutionPath parent, ExecutionPath child) { if (child == null) { return parent; } List<Object> segments = child.toList(); for (Object segment : segments) { if (segment instanceof Integer) { parent = parent.segment(((Integer) segment)); } else { parent = parent.segment((String.valueOf(segment))); } } return parent; }
Example 3
Source File: FederatedTracingInstrumentation.java From federation-jvm with MIT License | 4 votes |
/** * Get node for the given path in nodesByPath (creating it and its parents if needed). * * Note that {@link #treeLock}'s read lock must be held when calling this method. */ @NotNull private Node getOrCreateNode(ExecutionPath path) { // Fast path for when the node already exists. Node current = nodesByPath.get(path); if (current != null) return current; // Find the latest ancestor that exists in the map. List<Object> pathSegments = path.toList(); int currentSegmentIndex = pathSegments.size(); while (current == null) { if (currentSegmentIndex <= 0) { // The root path's node is inserted at construction time, so this shouldn't // happen. throw new RuntimeException("root path missing from nodesByPath?"); } currentSegmentIndex--; ExecutionPath currentPath = ExecutionPath.fromList(pathSegments.subList(0, currentSegmentIndex)); current = nodesByPath.get(currentPath); } // Travel back down to the requested node, creating child nodes along the way as // needed. for (; currentSegmentIndex < pathSegments.size(); currentSegmentIndex++) { Node parent = current; ExecutionPath childPath = ExecutionPath.fromList(pathSegments.subList(0, currentSegmentIndex + 1)); Object childSegment = pathSegments.get(currentSegmentIndex); Reports.Trace.Node.Builder childBuilder = Reports.Trace.Node.newBuilder(); if (childSegment instanceof Integer) { childBuilder.setIndex((Integer) childSegment); } else if (currentSegmentIndex < pathSegments.size() - 1) { // We've encountered a field name node that is an ancestor of the requested // node. However, the fetcher for that field name should have ultimately // called getOrCreateNode() on its node before getOrCreateNode() was called // on the requested node, meaning that this field name node should already // be in nodesByPath. Accordingly, we should never encounter such field // name ancestor nodes, and we throw when we do. throw new RuntimeException("Unexpected missing non-index " + childSegment); } Node childNode = new Node(childBuilder); // Note that putIfAbsent() here will give the child node if it already existed, // or null if it didn't (in which case the node passed to putIfAbsent() becomes // the child node). current = nodesByPath.putIfAbsent(childPath, childNode); if (current == null) { current = childNode; parent.children.add(childNode); } } return current; }