Skip to content

Commit

Permalink
Add sortOrder to schema and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Mar 22, 2024
1 parent aa8efd2 commit 02b6804
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 3 deletions.
1 change: 0 additions & 1 deletion docs/apis/GraphQL-Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ GraphQL query in the left hand panel of the page:
name
}
mode
bikesAllowed
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public DataFetcher<String> shortName() {
return environment -> getSource(environment).getShortName();
}

@Override
public DataFetcher<Integer> sortOrder() {
return env -> getSource(env).getGtfsSortOrder();
}

@Override
public DataFetcher<Iterable<Object>> stops() {
return this::getStops;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ public interface GraphQLQueryType {
public DataFetcher<Object> viewer();
}

public interface GraphQLRealtimeEstimate {
/** Real-time estimates for a vehicle at a certain place. */
public interface GraphQLRealTimeEstimate {
public DataFetcher<java.time.Duration> delay();

public DataFetcher<java.time.OffsetDateTime> time();
Expand Down Expand Up @@ -864,6 +865,8 @@ public interface GraphQLRoute {

public DataFetcher<String> shortName();

public DataFetcher<Integer> sortOrder();

public DataFetcher<Iterable<Object>> stops();

public DataFetcher<String> textColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,12 @@ type Route implements Node {
"""
types: [RouteAlertType]
): [Alert]

"""
Orders the routes in a way which is ideal for presentation to passengers.
Routes with smaller values should be displayed first.
"""
sortOrder: Int
}

"""Entities that are relevant for routes that can contain alerts"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static void setup() {
.route(m.name())
.withMode(m)
.withLongName(I18NString.of("Long name for %s".formatted(m)))
.withGtfsSortOrder(sortOrder(m))
.build()
)
.toList();
Expand Down Expand Up @@ -283,6 +284,17 @@ public TransitAlertService getTransitAlertService() {
);
}

/**
* We want to provide a variety of numbers and null.
*/
private static Integer sortOrder(TransitMode m) {
if (m.ordinal() == 0) {
return null;
} else {
return m.ordinal();
}
}

private static void add10MinuteDelay(Itinerary i1) {
i1.transformTransitLegs(tl -> {
if (tl instanceof ScheduledTransitLeg stl) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"data" : {
"routes" : [
{
"longName" : "Long name for CARPOOL",
"shortName" : "RCARPOOL",
"gtfsId" : "F:CARPOOL",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "CARPOOL",
"sortOrder" : 12
},
{
"longName" : "Long name for SUBWAY",
"shortName" : "RSUBWAY",
"gtfsId" : "F:SUBWAY",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "SUBWAY",
"sortOrder" : 2
},
{
"longName" : "Long name for BUS",
"shortName" : "RBUS",
"gtfsId" : "F:BUS",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "BUS",
"sortOrder" : 3
},
{
"longName" : "Long name for FERRY",
"shortName" : "RFERRY",
"gtfsId" : "F:FERRY",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "FERRY",
"sortOrder" : 5
},
{
"longName" : "Long name for COACH",
"shortName" : "RCOACH",
"gtfsId" : "F:COACH",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "COACH",
"sortOrder" : 1
},
{
"longName" : "Long name for TRAM",
"shortName" : "RTRAM",
"gtfsId" : "F:TRAM",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TRAM",
"sortOrder" : 4
},
{
"longName" : "Long name for CABLE_CAR",
"shortName" : "RCABLE_CAR",
"gtfsId" : "F:CABLE_CAR",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "CABLE_CAR",
"sortOrder" : 7
},
{
"longName" : "Long name for FUNICULAR",
"shortName" : "RFUNICULAR",
"gtfsId" : "F:FUNICULAR",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "FUNICULAR",
"sortOrder" : 9
},
{
"longName" : "Long name for RAIL",
"shortName" : "RRAIL",
"gtfsId" : "F:RAIL",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "RAIL",
"sortOrder" : null
},
{
"longName" : "Long name for MONORAIL",
"shortName" : "RMONORAIL",
"gtfsId" : "F:MONORAIL",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "MONORAIL",
"sortOrder" : 11
},
{
"longName" : "Long name for GONDOLA",
"shortName" : "RGONDOLA",
"gtfsId" : "F:GONDOLA",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "GONDOLA",
"sortOrder" : 8
},
{
"longName" : "Long name for TROLLEYBUS",
"shortName" : "RTROLLEYBUS",
"gtfsId" : "F:TROLLEYBUS",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TROLLEYBUS",
"sortOrder" : 10
},
{
"longName" : "Long name for AIRPLANE",
"shortName" : "RAIRPLANE",
"gtfsId" : "F:AIRPLANE",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "AIRPLANE",
"sortOrder" : 6
},
{
"longName" : "Long name for TAXI",
"shortName" : "RTAXI",
"gtfsId" : "F:TAXI",
"agency" : {
"gtfsId" : "F:A1",
"name" : "Agency Test"
},
"mode" : "TAXI",
"sortOrder" : 13
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
routes {
longName
shortName
gtfsId
agency {
gtfsId
name
}
mode
sortOrder
bikesAllowed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
name
}
mode
bikesAllowed
}
}

0 comments on commit 02b6804

Please sign in to comment.