graphql.nadel.engine.execution.PathMapper Maven / Gradle / Ivy
Show all versions of nadel-engine Show documentation
package graphql.nadel.engine.execution;
import graphql.Internal;
import graphql.execution.ResultPath;
import java.util.ArrayList;
import java.util.List;
@Internal
public class PathMapper {
/**
* This function corrects the given {@code executionPath} by taking the parent path
* and appending the last child segment to it. It also replaces the last String path
* segment with {@code resultKey}.
*
* There are two reasons for using the parent path:
*
* Firstly, to fix hydration paths i.e. the {@code executionPath} will be the hydrated
* field path and the parent path will be where the hydrated object is stitched in and
* we need to merge those two paths.
*
* e.g. if we hydrate {@code reporter} here
*
{@code
* type Issue {
* reporter: User => hydrated from Users.user(id: $source.reporterId)
* }
* }
* Then the {@code executionPath} could be {@code /user/name} and the parent path would
* be {@code /issue/reporter} and the desired path would be {@code /issue/reporter/name}
*
* Secondly, to fix renamed paths e.g. given the parent path {@code /devOpsRelationships}
* and given the {@code executionPath} {@code /relationships/nodes}
*
* where the field {@code relationships} was renamed to {@code devOpsRelationships}
*
* we should take the renamed parent path {@code /devopsRelationships}
*
* and append the child path {@code nodes} to it
*
* @param executionPath the path to correct
* @param resultKey the correct segment name to use
* @param environment context for the current path
* @return the fixed path as described above
*/
public ResultPath mapPath(ResultPath executionPath, String resultKey, UnapplyEnvironment environment) {
List