Skip to content

Commit

Permalink
Allow using feeds parameter without name parameter also for stations …
Browse files Browse the repository at this point in the history
…query
  • Loading branch information
mjaakko committed Apr 1, 2020
1 parent c7ee6ec commit cbbda17
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -2963,6 +2963,11 @@ private Object getObject(String idString) {
.description("Only return stations that match one of the ids in this list")
.type(new GraphQLList(Scalars.GraphQLString))
.build())
.argument(GraphQLArgument.newArgument()
.name("feeds")
.description("List of feeds from which stations are returned. Defaults to all feeds")
.type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLString)))
.build())
.argument(GraphQLArgument.newArgument()
.name("name")
.description("Query stations by name")
Expand All @@ -2973,11 +2978,6 @@ private Object getObject(String idString) {
.description("Number of results to return when using `name` argument. Defaults to 10")
.type(Scalars.GraphQLInt)
.build())
.argument(GraphQLArgument.newArgument()
.name("feeds")
.description("List of feeds from which stations are returned when using `name` argument. Defaults to all feeds")
.type(GraphQLList.list(GraphQLNonNull.nonNull(Scalars.GraphQLString)))
.build())
.dataFetcher(environment -> {
if ((environment.getArgument("ids") instanceof List)) {
if (environment.getArguments().entrySet()
Expand All @@ -2995,7 +2995,12 @@ private Object getObject(String idString) {

Stream<Stop> stream;
if (environment.getArgument("name") == null) {
stream = index.stationForId.values().stream();
if (environment.getArgument("feeds") == null) {
stream = index.stationForId.values().stream();
} else {
List<String> feedIds = environment.getArgument("feeds");
stream = index.stationForId.values().stream().filter(station -> feedIds.contains(station.getId().getAgencyId()));
}
} else {
int maxResults = environment.getArgument("maxResults") != null ? environment.getArgument("maxResults") : 10;
List<String> feeds = environment.getArgument("feeds");
Expand Down

0 comments on commit cbbda17

Please sign in to comment.