Skip to content

Commit

Permalink
fix(gtfs-api): use post method for long variable lists in graphql que…
Browse files Browse the repository at this point in the history
…ries
  • Loading branch information
landonreed committed Jun 30, 2017
1 parent b632710 commit e2722a8
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/gtfs/actions/general.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetch from 'isomorphic-fetch'

import { clearStops } from './stops'
import { clearPatterns } from './patterns'
import { clearRoutes } from './routes'
Expand All @@ -13,13 +14,15 @@ export function clearGtfsElements () {
dispatch(clearPatterns())
}
}

function requestGtfsElements (feedIds, entities) {
return {
type: 'REQUESTING_GTFS_ELEMENTS',
feedIds,
entities
}
}

function receivedGtfsElements (feedIds, stops, patterns) {
return {
type: 'RECEIVED_GTFS_ELEMENTS',
Expand All @@ -28,6 +31,7 @@ function receivedGtfsElements (feedIds, stops, patterns) {
patterns
}
}

export const requestStopsAndRoutes = (feedIds, routeids, stopIds, module) => {
return {
type: 'REQUEST_GTFS_STOPS_AND_ROUTES',
Expand All @@ -37,13 +41,15 @@ export const requestStopsAndRoutes = (feedIds, routeids, stopIds, module) => {
module
}
}

export const receivedStopsAndRoutes = (results, module) => {
return {
type: 'RECEIVED_GTFS_STOPS_AND_ROUTES',
results,
module
}
}

export function fetchStopsAndRoutes (entities, module) {
return function (dispatch, getState) {
const activeProject = getActiveProject(getState())
Expand All @@ -66,16 +72,18 @@ export function fetchStopsAndRoutes (entities, module) {
stopId.push(e.entity.StopId)
}
})
const method = 'post'
const body = JSON.stringify({
query: stopsAndRoutes(feedId, routeId, stopId),
variables: JSON.stringify({feedId, routeId, stopId})
})
dispatch(requestStopsAndRoutes(feedId, routeId, stopId, module))
return fetch(compose(stopsAndRoutes(feedId, routeId, stopId), {feedId, routeId, stopId}))
.then((response) => {
return response.json()
})
.then(results => {
return dispatch(receivedStopsAndRoutes(results, module))
})
return fetch(`/api/manager/graphql`, {method, body})
.then(response => response.json())
.then(results => dispatch(receivedStopsAndRoutes(results, module)))
}
}

export function refreshGtfsElements (feedId, entities) {
return function (dispatch, getState) {
dispatch(requestGtfsElements(feedId, entities))
Expand Down

0 comments on commit e2722a8

Please sign in to comment.