Skip to content

Commit

Permalink
Merge pull request #5835 from HSLdevcom/publisher-query
Browse files Browse the repository at this point in the history
Add feed publisher name and url to GTFS GraphQL API
  • Loading branch information
optionsome authored Jun 3, 2024
2 parents b567ac5 + a181803 commit ef6c705
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ protected static GraphQLSchema buildSchema() {
.type(typeWiring.build(DepartureRowImpl.class))
.type(typeWiring.build(elevationProfileComponentImpl.class))
.type(typeWiring.build(FeedImpl.class))
.type(typeWiring.build(FeedImpl.class))
.type(typeWiring.build(GeometryImpl.class))
.type(typeWiring.build(ItineraryImpl.class))
.type(typeWiring.build(LegImpl.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.opentripplanner.apis.gtfs.GraphQLRequestContext;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.apis.gtfs.model.FeedPublisher;
import org.opentripplanner.routing.alertpatch.EntitySelector;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.routing.services.TransitAlertService;
Expand Down Expand Up @@ -64,6 +65,17 @@ public DataFetcher<String> feedId() {
return this::getSource;
}

@Override
public DataFetcher<FeedPublisher> publisher() {
return environment -> {
String id = getSource(environment);
return new FeedPublisher(
getTransitService(environment).getFeedInfo(id).getPublisherName(),
getTransitService(environment).getFeedInfo(id).getPublisherUrl()
);
};
}

private List<Agency> getAgencies(DataFetchingEnvironment environment) {
String id = getSource(environment);
return getTransitService(environment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRelativeDirection;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLRoutingErrorCode;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLTransitMode;
import org.opentripplanner.apis.gtfs.model.FeedPublisher;
import org.opentripplanner.apis.gtfs.model.RideHailingProvider;
import org.opentripplanner.apis.gtfs.model.StopPosition;
import org.opentripplanner.apis.gtfs.model.TripOccupancy;
Expand Down Expand Up @@ -380,6 +381,15 @@ public interface GraphQLFeed {
public DataFetcher<Iterable<TransitAlert>> alerts();

public DataFetcher<String> feedId();

public DataFetcher<FeedPublisher> publisher();
}

/** Feed publisher information */
public interface GraphQLFeedPublisher {
public DataFetcher<String> name();

public DataFetcher<String> url();
}

public interface GraphQLGeometry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ config:
elevationProfileComponent: org.opentripplanner.model.plan.ElevationProfile.Step
Emissions: org.opentripplanner.model.plan.Emissions#Emissions
Feed: String
FeedPublisher: org.opentripplanner.apis.gtfs.model.FeedPublisher#FeedPublisher
Geometry: org.locationtech.jts.geom.Geometry#Geometry
InputField: org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLInputField#GraphQLInputField
Itinerary: org.opentripplanner.model.plan.Itinerary#Itinerary
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.opentripplanner.apis.gtfs.model;

import java.util.Objects;

public record FeedPublisher(String name, String url) {
public FeedPublisher {
Objects.requireNonNull(name);
Objects.requireNonNull(url);
}
}
15 changes: 15 additions & 0 deletions src/main/resources/org/opentripplanner/apis/gtfs/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,18 @@ type fareComponent {
routes: [Route] @deprecated
}


"""
Feed publisher information
"""
type FeedPublisher {
"""Name of feed publisher"""
name: String!

"""Web address of feed publisher"""
url: String!
}

"""
A feed provides routing data (stops, routes, timetables, etc.) from one or more public transport agencies.
"""
Expand All @@ -984,6 +996,9 @@ type Feed {
"""List of agencies which provide data to this feed"""
agencies: [Agency]

"The publisher of the input transit data."
publisher: FeedPublisher

"""
Alerts relevant for the feed.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.framework.model.Grams;
import org.opentripplanner.model.FeedInfo;
import org.opentripplanner.model.fare.FareMedium;
import org.opentripplanner.model.fare.FareProduct;
import org.opentripplanner.model.fare.ItineraryFares;
Expand Down Expand Up @@ -84,6 +85,7 @@
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.network.BikeAccess;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.site.StopLocation;
import org.opentripplanner.transit.model.timetable.RealTimeTripTimes;
Expand Down Expand Up @@ -151,6 +153,18 @@ static void setup() {

transitModel.addTripPattern(id("pattern-1"), pattern);

var feedId = "testfeed";
var feedInfo = FeedInfo.dummyForTest(feedId);
transitModel.addFeedInfo(feedInfo);

var agency = Agency
.of(new FeedScopedId(feedId, "agency-xx"))
.withName("speedtransit")
.withUrl("www.otp-foo.bar")
.withTimezone("Europe/Berlin")
.build();
transitModel.addAgency(agency);

transitModel.initTimeZone(ZoneIds.BERLIN);
transitModel.index();
var routes = Arrays
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"data" : {
"feeds" : [
{
"agencies" : [
{
"name" : "speedtransit",
"url" : "www.otp-foo.bar"
}
],
"publisher" : {
"name" : "publisher",
"url" : "www.z.org"
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
feeds {
agencies {
name
url
}
publisher {
name
url
}
}
}

0 comments on commit ef6c705

Please sign in to comment.