Skip to content

Commit ea2d4e1

Browse files
authored
expose arrive_by flag in directions GraphQL API (#567)
* expose tlrouter's arriveBy flag in graphql * add documentation * regenerate * more systematic support for routing backends * tests * back to simpler * remove line break
1 parent 919fe02 commit ea2d4e1

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

internal/generated/gqlout/generated.go

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/graphql/directions.graphqls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ input DirectionRequest {
44
to: WaypointInput!
55
from: WaypointInput!
66
mode: StepMode!
7+
"Departure time; treated as arrival time when arrive_by is true. Defaults to now."
78
depart_at: Time
9+
"If true, treat depart_at as the desired arrival time rather than departure time. Support depends on the configured routing provider."
10+
arrive_by: Boolean
811
}
912

1013
input WaypointInput {

server/directions/tlrouter/tlrouter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func (h *Router) Request(ctx context.Context, req model.DirectionRequest) (*mode
9393
departAt = departAt.In(time.UTC)
9494
input.UnixTime = departAt.Unix()
9595

96+
// Set arrive_by flag
97+
if req.ArriveBy != nil && *req.ArriveBy {
98+
input.ArriveBy = true
99+
}
100+
96101
// Make request
97102
res, err := makeRequest(ctx, input, h.client, h.endpoint, h.apikey)
98103
if err != nil || len(res.Plan.Itineraries) == 0 {
@@ -119,6 +124,9 @@ func makeRequest(ctx context.Context, req Request, client *http.Client, endpoint
119124
q.Add("unixTime", fmt.Sprintf("%d", req.UnixTime))
120125
q.Add("mode", req.Mode)
121126
q.Add("includeWalkingItinerary", "true")
127+
if req.ArriveBy {
128+
q.Add("arriveBy", "true")
129+
}
122130
if req.UseFallbackDates {
123131
q.Add("useFallbackDates", "true")
124132
}

server/model/models_gen.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)