|
1 | 1 | package org.opentripplanner.index;
|
2 | 2 |
|
3 |
| -import com.google.common.collect.ImmutableMap; |
4 |
| -import com.vividsolutions.jts.geom.Coordinate; |
5 |
| -import com.vividsolutions.jts.geom.Envelope; |
6 |
| -import com.vividsolutions.jts.geom.LineString; |
7 |
| -import graphql.Scalars; |
8 |
| -import graphql.relay.Relay; |
9 |
| -import graphql.relay.SimpleListConnection; |
10 |
| -import graphql.schema.DataFetcher; |
11 |
| -import graphql.schema.DataFetchingEnvironment; |
12 |
| -import graphql.schema.DataFetchingEnvironmentImpl; |
13 |
| -import graphql.schema.GraphQLArgument; |
14 |
| -import graphql.schema.GraphQLEnumType; |
15 |
| -import graphql.schema.GraphQLFieldDefinition; |
16 |
| -import graphql.schema.GraphQLInputObjectField; |
17 |
| -import graphql.schema.GraphQLInputObjectType; |
18 |
| -import graphql.schema.GraphQLInterfaceType; |
19 |
| -import graphql.schema.GraphQLList; |
20 |
| -import graphql.schema.GraphQLNonNull; |
21 |
| -import graphql.schema.GraphQLObjectType; |
22 |
| -import graphql.schema.GraphQLOutputType; |
23 |
| -import graphql.schema.GraphQLSchema; |
24 |
| -import graphql.schema.GraphQLType; |
25 |
| -import graphql.schema.GraphQLTypeReference; |
26 |
| -import graphql.schema.PropertyDataFetcher; |
27 |
| -import graphql.schema.TypeResolver; |
| 3 | +import static java.util.Collections.emptyList; |
| 4 | + |
| 5 | +import java.text.ParseException; |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.BitSet; |
| 9 | +import java.util.Collection; |
| 10 | +import java.util.Collections; |
| 11 | +import java.util.Comparator; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.HashSet; |
| 14 | +import java.util.List; |
| 15 | +import java.util.Map; |
| 16 | +import java.util.Objects; |
| 17 | +import java.util.Set; |
| 18 | +import java.util.stream.Collectors; |
| 19 | +import java.util.stream.Stream; |
| 20 | + |
28 | 21 | import org.onebusaway.gtfs.model.Agency;
|
29 | 22 | import org.onebusaway.gtfs.model.AgencyAndId;
|
30 | 23 | import org.onebusaway.gtfs.model.Route;
|
|
55 | 48 | import org.opentripplanner.routing.core.Money;
|
56 | 49 | import org.opentripplanner.routing.core.OptimizeType;
|
57 | 50 | import org.opentripplanner.routing.core.ServiceDay;
|
| 51 | +import org.opentripplanner.routing.core.TicketType; |
58 | 52 | import org.opentripplanner.routing.core.TraverseMode;
|
59 | 53 | import org.opentripplanner.routing.edgetype.SimpleTransfer;
|
60 | 54 | import org.opentripplanner.routing.edgetype.Timetable;
|
|
71 | 65 | import org.opentripplanner.util.TranslatedString;
|
72 | 66 | import org.opentripplanner.util.model.EncodedPolylineBean;
|
73 | 67 |
|
74 |
| -import java.text.ParseException; |
75 |
| -import java.util.*; |
76 |
| -import java.util.stream.Collectors; |
77 |
| -import java.util.stream.Stream; |
| 68 | +import com.google.common.collect.ImmutableMap; |
| 69 | +import com.vividsolutions.jts.geom.Coordinate; |
| 70 | +import com.vividsolutions.jts.geom.Envelope; |
| 71 | +import com.vividsolutions.jts.geom.LineString; |
78 | 72 |
|
79 |
| -import static java.util.Collections.emptyList; |
| 73 | +import graphql.Scalars; |
| 74 | +import graphql.relay.Relay; |
| 75 | +import graphql.relay.SimpleListConnection; |
| 76 | +import graphql.schema.DataFetcher; |
| 77 | +import graphql.schema.DataFetchingEnvironment; |
| 78 | +import graphql.schema.DataFetchingEnvironmentImpl; |
| 79 | +import graphql.schema.GraphQLArgument; |
| 80 | +import graphql.schema.GraphQLEnumType; |
| 81 | +import graphql.schema.GraphQLFieldDefinition; |
| 82 | +import graphql.schema.GraphQLInputObjectField; |
| 83 | +import graphql.schema.GraphQLInputObjectType; |
| 84 | +import graphql.schema.GraphQLInterfaceType; |
| 85 | +import graphql.schema.GraphQLList; |
| 86 | +import graphql.schema.GraphQLNonNull; |
| 87 | +import graphql.schema.GraphQLObjectType; |
| 88 | +import graphql.schema.GraphQLOutputType; |
| 89 | +import graphql.schema.GraphQLSchema; |
| 90 | +import graphql.schema.GraphQLType; |
| 91 | +import graphql.schema.GraphQLTypeReference; |
| 92 | +import graphql.schema.PropertyDataFetcher; |
| 93 | +import graphql.schema.TypeResolver; |
80 | 94 |
|
81 | 95 | public class IndexGraphQLSchema {
|
| 96 | + |
| 97 | + public static String experimental(String message) { |
| 98 | + return String.format("!!This api is experimental and might change without further notice!!\n %s", message); |
| 99 | + } |
82 | 100 |
|
83 | 101 | public static GraphQLEnumType locationTypeEnum = GraphQLEnumType.newEnum()
|
84 | 102 | .name("LocationType")
|
@@ -168,6 +186,8 @@ public class IndexGraphQLSchema {
|
168 | 186 | private final GtfsRealtimeFuzzyTripMatcher fuzzyTripMatcher;
|
169 | 187 |
|
170 | 188 | public GraphQLOutputType agencyType = new GraphQLTypeReference("Agency");
|
| 189 | + |
| 190 | + public GraphQLOutputType ticketType = new GraphQLTypeReference("TicketType"); |
171 | 191 |
|
172 | 192 | public GraphQLOutputType alertType = new GraphQLTypeReference("Alert");
|
173 | 193 |
|
@@ -305,16 +325,6 @@ private Agency getAgency(GraphIndex index, String agencyId) {
|
305 | 325 | return null;
|
306 | 326 | }
|
307 | 327 |
|
308 |
| - private List<Agency> getAllAgencies(GraphIndex index) { |
309 |
| - //xxx what if there are duplciate agency ids? |
310 |
| - //now we return the first |
311 |
| - ArrayList<Agency> agencies = new ArrayList<Agency>(); |
312 |
| - for (Map<String, Agency> feedAgencies : index.agenciesForFeedId.values()) { |
313 |
| - agencies.addAll(feedAgencies.values()); |
314 |
| - } |
315 |
| - return agencies; |
316 |
| - } |
317 |
| - |
318 | 328 | @SuppressWarnings("unchecked")
|
319 | 329 | public IndexGraphQLSchema(GraphIndex index) {
|
320 | 330 | createPlanType(index);
|
@@ -635,6 +645,11 @@ public IndexGraphQLSchema(GraphIndex index) {
|
635 | 645 | .description("Locale for returned text")
|
636 | 646 | .type(Scalars.GraphQLString)
|
637 | 647 | .build())
|
| 648 | + .argument(GraphQLArgument.newArgument() |
| 649 | + .name("ticketTypes") |
| 650 | + .description("Allowed ticket types") |
| 651 | + .type(Scalars.GraphQLString) |
| 652 | + .build()) |
638 | 653 | .dataFetcher(environment -> new GraphQlPlanner(index).plan(environment))
|
639 | 654 | .build();
|
640 | 655 |
|
@@ -1822,6 +1837,30 @@ public IndexGraphQLSchema(GraphIndex index) {
|
1822 | 1837 | .build())
|
1823 | 1838 | .build();
|
1824 | 1839 |
|
| 1840 | + ticketType = GraphQLObjectType.newObject() |
| 1841 | + .name("TicketType") |
| 1842 | + .description(experimental("Describes ticket type")) |
| 1843 | + .withInterface(nodeInterface) |
| 1844 | + .field(GraphQLFieldDefinition.newFieldDefinition() |
| 1845 | + .name("id") |
| 1846 | + .type(new GraphQLNonNull(Scalars.GraphQLID)) |
| 1847 | + .dataFetcher(environment -> relay |
| 1848 | + .toGlobalId(ticketType.getName(), ((TicketType) environment.getSource()).getId())) |
| 1849 | + .build()) |
| 1850 | + .field(GraphQLFieldDefinition.newFieldDefinition() |
| 1851 | + .name("fareId") |
| 1852 | + .type(new GraphQLNonNull(Scalars.GraphQLID)) |
| 1853 | + .dataFetcher(environment -> ((TicketType) environment.getSource()).getId()) |
| 1854 | + .build()) |
| 1855 | + .field(GraphQLFieldDefinition.newFieldDefinition() |
| 1856 | + .name("price") |
| 1857 | + .type(Scalars.GraphQLFloat) |
| 1858 | + .dataFetcher(environment -> ((TicketType) environment.getSource()).getPrice()) |
| 1859 | + .build() |
| 1860 | + ) |
| 1861 | + .build(); |
| 1862 | + |
| 1863 | + |
1825 | 1864 | carParkType = GraphQLObjectType.newObject()
|
1826 | 1865 | .name("CarPark")
|
1827 | 1866 | .withInterface(nodeInterface)
|
@@ -1979,6 +2018,13 @@ private Object getObject(String idString) {
|
1979 | 2018 | .type(new GraphQLList(agencyType))
|
1980 | 2019 | .dataFetcher(environment -> new ArrayList<>(index.getAllAgencies()))
|
1981 | 2020 | .build())
|
| 2021 | + .field(GraphQLFieldDefinition.newFieldDefinition() |
| 2022 | + .name("ticketTypes") |
| 2023 | + .description(experimental("Return list of available ticket types.")) |
| 2024 | + .type(new GraphQLList(ticketType)) |
| 2025 | + .dataFetcher(environment -> new ArrayList<>(index.getAllTicketTypes())) |
| 2026 | + .build() |
| 2027 | + ) |
1982 | 2028 | .field(GraphQLFieldDefinition.newFieldDefinition()
|
1983 | 2029 | .name("agency")
|
1984 | 2030 | .description("Get a single agency based on agency ID")
|
|
0 commit comments