All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLDepartureRowImpl Maven / Gradle / Ivy

package org.opentripplanner.ext.legacygraphqlapi.datafetchers;

import graphql.relay.Relay;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLTypes;
import org.opentripplanner.model.TripPattern;
import org.opentripplanner.model.TripTimeShort;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.routing.graphfinder.PatternAtStop;

public class LegacyGraphQLDepartureRowImpl
    implements LegacyGraphQLDataFetchers.LegacyGraphQLDepartureRow {

  @Override
  public DataFetcher id() {
    return environment -> new Relay.ResolvedGlobalId("DepartureRow", getSource(environment).id);
  }

  @Override
  public DataFetcher stop() {
    return environment -> getSource(environment).stop;
  }

  @Override
  public DataFetcher lat() {
    return environment -> getSource(environment).stop.getLat();
  }

  @Override
  public DataFetcher lon() {
    return environment -> getSource(environment).stop.getLon();
  }

  @Override
  public DataFetcher pattern() {
    return environment -> getSource(environment).pattern;
  }

  @Override
  public DataFetcher> stoptimes() {
    return environment -> {
      LegacyGraphQLTypes.LegacyGraphQLDepartureRowStoptimesArgs args = new LegacyGraphQLTypes.LegacyGraphQLDepartureRowStoptimesArgs(environment.getArguments());
      return getSource(environment).getStoptimes(
          getRoutingService(environment),
          args.getLegacyGraphQLStartTime(),
          args.getLegacyGraphQLTimeRange(),
          args.getLegacyGraphQLNumberOfDepartures(),
          args.getLegacyGraphQLOmitNonPickups(),
          args.getLegacyGraphQLOmitCanceled()
      );
    };
  }

  private RoutingService getRoutingService(DataFetchingEnvironment environment) {
    return environment.getContext().getRoutingService();
  }

  private PatternAtStop getSource(DataFetchingEnvironment environment) {
    return environment.getSource();
  }
}