Skip to content

Commit

Permalink
add previousLegs into GTFS GraphQL API
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Oct 10, 2024
1 parent 155d19b commit 124f589
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,17 @@ private Leg getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}

@Override
public DataFetcher<Iterable<Leg>> previousLegs() {
return nextOrPreviousLegs(true);
}

@Override
public DataFetcher<Iterable<Leg>> nextLegs() {
return nextOrPreviousLegs(false);
}

private DataFetcher<Iterable<Leg>> nextOrPreviousLegs(boolean includeDepartBefore) {
return environment -> {
if (environment.getSource() instanceof ScheduledTransitLeg originalLeg) {
var args = new GraphQLTypes.GraphQLLegNextLegsArgs(environment.getArguments());
Expand Down Expand Up @@ -307,7 +316,7 @@ public DataFetcher<Iterable<Leg>> nextLegs() {
environment.getSource(),
numberOfLegs,
environment.<GraphQLRequestContext>getContext().transitService(),
false,
includeDepartBefore,
AlternativeLegsFilter.NO_FILTER,
limitToExactOriginStop,
limitToExactDestinationStop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
package org.opentripplanner.apis.gtfs.generated;

import graphql.relay.Connection;
import graphql.relay.Connection;
import graphql.relay.DefaultEdge;
import graphql.relay.Edge;
import graphql.relay.Edge;
import graphql.schema.DataFetcher;
import graphql.schema.TypeResolver;
import java.util.Currency;
Expand All @@ -24,8 +26,12 @@
import org.opentripplanner.apis.gtfs.model.FeedPublisher;
import org.opentripplanner.apis.gtfs.model.PlanPageInfo;
import org.opentripplanner.apis.gtfs.model.RideHailingProvider;
import org.opentripplanner.apis.gtfs.model.RouteTypeModel;
import org.opentripplanner.apis.gtfs.model.StopOnRouteModel;
import org.opentripplanner.apis.gtfs.model.StopOnTripModel;
import org.opentripplanner.apis.gtfs.model.StopPosition;
import org.opentripplanner.apis.gtfs.model.TripOccupancy;
import org.opentripplanner.apis.gtfs.model.UnknownModel;
import org.opentripplanner.ext.fares.model.FareRuleSet;
import org.opentripplanner.ext.ridehailing.model.RideEstimate;
import org.opentripplanner.model.StopTimesInPattern;
Expand All @@ -48,6 +54,8 @@
import org.opentripplanner.routing.graphfinder.PatternAtStop;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingSpaces;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingState;
import org.opentripplanner.service.realtimevehicles.model.RealtimeVehicle;
Expand All @@ -58,6 +66,7 @@
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle;
import org.opentripplanner.transit.model.basic.Money;
Expand Down Expand Up @@ -500,6 +509,8 @@ public interface GraphQLLeg {

public DataFetcher<String> pickupType();

public DataFetcher<Iterable<Leg>> previousLegs();

public DataFetcher<Boolean> realTime();

public DataFetcher<String> realtimeState();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
package org.opentripplanner.apis.gtfs.generated;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1268,6 +1269,69 @@ public void setGraphQLOriginModesWithParentStation(
}
}

public static class GraphQLLegPreviousLegsArgs {

private List<GraphQLTransitMode> destinationModesWithParentStation;
private Integer numberOfLegs;
private List<GraphQLTransitMode> originModesWithParentStation;

public GraphQLLegPreviousLegsArgs(Map<String, Object> args) {
if (args != null) {
if (args.get("destinationModesWithParentStation") != null) {
this.destinationModesWithParentStation =
((List<Object>) args.get("destinationModesWithParentStation")).stream()
.map(item ->
item instanceof GraphQLTransitMode
? item
: GraphQLTransitMode.valueOf((String) item)
)
.map(GraphQLTransitMode.class::cast)
.collect(Collectors.toList());
}
this.numberOfLegs = (Integer) args.get("numberOfLegs");
if (args.get("originModesWithParentStation") != null) {
this.originModesWithParentStation =
((List<Object>) args.get("originModesWithParentStation")).stream()
.map(item ->
item instanceof GraphQLTransitMode
? item
: GraphQLTransitMode.valueOf((String) item)
)
.map(GraphQLTransitMode.class::cast)
.collect(Collectors.toList());
}
}
}

public List<GraphQLTransitMode> getGraphQLDestinationModesWithParentStation() {
return this.destinationModesWithParentStation;
}

public Integer getGraphQLNumberOfLegs() {
return this.numberOfLegs;
}

public List<GraphQLTransitMode> getGraphQLOriginModesWithParentStation() {
return this.originModesWithParentStation;
}

public void setGraphQLDestinationModesWithParentStation(
List<GraphQLTransitMode> destinationModesWithParentStation
) {
this.destinationModesWithParentStation = destinationModesWithParentStation;
}

public void setGraphQLNumberOfLegs(Integer numberOfLegs) {
this.numberOfLegs = numberOfLegs;
}

public void setGraphQLOriginModesWithParentStation(
List<GraphQLTransitMode> originModesWithParentStation
) {
this.originModesWithParentStation = originModesWithParentStation;
}
}

public static class GraphQLLocalDateRangeInput {

private java.time.LocalDate end;
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,24 @@ type Leg {
pickupBookingInfo: BookingInfo
"This is used to indicate if boarding this leg is possible only with special arrangements."
pickupType: PickupDropoffType
"Previous legs with same origin and destination stops or stations"
previousLegs(
"""
Transportation modes for which all stops in the parent station are used as possible destination stops
for the previous legs. For modes not listed, only the exact destination stop of the leg is considered.
"""
destinationModesWithParentStation: [TransitMode!],
"""
The number of alternative legs searched. If fewer than the requested number are found,
then only the found legs are returned.
"""
numberOfLegs: Int!,
"""
Transportation modes for which all stops in the parent station are used as possible origin stops
for the previous legs. For modes not listed, only the exact origin stop of the leg is considered.
"""
originModesWithParentStation: [TransitMode!]
): [Leg!]
"Whether there is real-time data about this Leg"
realTime: Boolean
"State of real-time data"
Expand Down

0 comments on commit 124f589

Please sign in to comment.