lib/generate.js
/**
 * Query a single feed via the GTFS API, load the stops/routes, and preprocess
 * for rendering
 *
 * @param {String} feedId the feed's unique ID in the GTFS API
 */
Query a single feed via the GTFS API, load the stops/routes, and preprocess
for rendering

@param {String} feedId the feed's unique ID in the GTFS API
Query a single feed via the GTFS API load the stops / routes and preprocess for rendering @param { String } feedId the feed ' s unique ID in the GTFS API
function queryFeed (feedId) {
  return new Promise((resolve, reject) => {
    const routeQuery = `
      query routeQuery ($feedId: String) {
        feeds (feed_id: [$feedId]) {
          feed_id,
          routes {
            route_id
            route_short_name
            route_long_name
            patterns {
              pattern_id
              geometry
            }
          }
          stops {
            stop_lat
            stop_lon
          }
        }
      }
    `
    const vars = `{ "feedId": "${feedId}" }`
    const url = `${config.api.gtfs}?query=${encodeURIComponent(routeQuery)}&variables=${encodeURIComponent(vars)}`
    fetch(url).then(res => {
      return res.json()
    })
      .then(response => {
        fs.writeFile(`cache/${feedId}.json`, JSON.stringify(response), err => {
          if (err) console.log(err)
        })
        resolve(processFeed(response))
      })
      .catch(err => {
        console.error(err)
      })
  })
}
function queryFeed ( feedId ) { return new Promise ( ( resolve , reject ) => { const routeQuery = ` ` const vars = ` ${ feedId } ` const url = ` ${ config . api . gtfs } ${ encodeURIComponent ( routeQuery ) } ${ encodeURIComponent ( vars ) } ` fetch ( url ) . then ( res => { return res . json ( ) } ) . then ( response => { fs . writeFile ( ` ${ feedId } ` , JSON . stringify ( response ) , err => { if ( err ) console . log ( err ) } ) resolve ( processFeed ( response ) ) } ) . catch ( err => { console . error ( err ) } ) } ) }
Query a single feed via the GTFS API, load the stops/routes, and preprocess
 for rendering
Query a single feed via the GTFS API load the stops / routes and preprocess for rendering
// set up the graphql query/variables and construct the url // write json to cache