If you are not yet familiar with GraphQL and GraphiQL it is highly recommended to review those pages at first.
Term | Explanation |
---|---|
Trip on service date | A specific departure with specific direction for a specific route. For example: tram 15 leaving from Keilaniemi on 2024-12-18 at 13:13. |
Graphql Cursor Connection | Special GraphQL query structure that introduces parameters and fields that can be used in pagination |
Canceled trips are trip times for which the whole departure has been canceled (i.e. not departures where only some stops are skipped). There are two types of trip cancelations: real-time and planned cancellations. Our data feeds only support real-time cancellations for now. If there is a known planned cancellation, it's possible that the whole trip is missing from the data feed and the canceled trips query doesn't therefore return it.
Note: Canceled trips do not include a reason why the departure has been canceled unless it's specified in an alert.
Usually, there are only a few canceled trips. However, it's highly recommended to use pagination to fetch canceled trips because in theory all trips can be canceled due to a strike, for example, which quickly increases the number of returned trips to tens of thousands which can really slow down the query (potentially even to the extent that the query is impossible to execute due to a timeout).
The query for canceled trips uses Relay Graphql Cursor Connection structure. It introduces first
and last
arguments for controlling how many trips are returned from the query. before
and after
parameters can be used to specify a cursor for where to continue the pagination. first
can be used alone without any other fields or together with after
. last
should be used with before
parameter. Usually, it's enough to use the first
and after
for pagination and the other pagination direction is not as useful in this context. It's possible to fetch pageInfo
which tells if there are more pages available and provides the necessary cursor(s) to continue the pagination.
The returned trips are sorted by departure time and date (earliest comes first).
Note: For more details about the query type alerts you can use the Documentation Explorer provided in GraphiQL.
{
canceledTrips(first: 100) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
serviceDate
trip {
gtfsId
alerts (types:ROUTE) {
alertHeaderText
alertDescriptionText
}
}
start {
stopLocation {
... on Stop {
name
}
}
schedule {
time {
... on ArrivalDepartureTime {
departure
}
}
}
realTime {
departure {
delay
time
}
}
}
end {
stopLocation {
... on Stop {
name
}
}
schedule {
time {
... on ArrivalDepartureTime {
arrival
}
}
}
realTime {
arrival {
delay
time
}
}
}
}
}
}
}
{
canceledTrips(first: 100, after: <endCursor from a previous query>) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
serviceDate
trip {
gtfsId
alerts (types:ROUTE) {
alertHeaderText
alertDescriptionText
}
}
start {
stopLocation {
... on Stop {
name
}
}
schedule {
time {
... on ArrivalDepartureTime {
departure
}
}
}
realTime {
departure {
delay
time
}
}
}
end {
stopLocation {
... on Stop {
name
}
}
schedule {
time {
... on ArrivalDepartureTime {
arrival
}
}
}
realTime {
arrival {
delay
time
}
}
}
}
}
}
}
after
parameter's value from a previous query's endCursor
.