org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLplaceAtDistanceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;
import graphql.TypeResolutionEnvironment;
import graphql.relay.Relay;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.DataFetchingEnvironmentImpl;
import graphql.schema.FieldCoordinates;
import graphql.schema.GraphQLInterfaceType;
import graphql.schema.GraphQLObjectType;
import graphql.schema.TypeResolver;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
public class LegacyGraphQLplaceAtDistanceImpl
implements LegacyGraphQLDataFetchers.LegacyGraphQLPlaceAtDistance {
@Override
public DataFetcher id() {
return environment -> {
PlaceAtDistance placeAtDistance = getSource(environment);
Object place = placeAtDistance.place;
TypeResolver typeResolver = new LegacyGraphQLPlaceInterfaceTypeResolver();
GraphQLInterfaceType placeInterface = (GraphQLInterfaceType) environment.getGraphQLSchema().getType("PlaceInterface");
GraphQLObjectType placeType = typeResolver.getType(new TypeResolutionEnvironment(
place,
environment.getArguments(),
environment.getMergedField(),
placeInterface,
environment.getGraphQLSchema(),
environment.getContext()
));
Relay.ResolvedGlobalId globalId = (Relay.ResolvedGlobalId) environment
.getGraphQLSchema()
.getCodeRegistry()
.getDataFetcher(
FieldCoordinates.coordinates(placeType.getName(), "id"),
placeInterface.getFieldDefinition("id")
).get(
DataFetchingEnvironmentImpl.newDataFetchingEnvironment(environment).source(place).build());
return new Relay.ResolvedGlobalId(
"placeAtDistance",
placeAtDistance.distance + ";" + new Relay().toGlobalId(globalId.getType(), globalId.getId())
);
};
}
@Override
public DataFetcher
© 2015 - 2025 Weber Informatics LLC | Privacy Policy