Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make query-gen agnostic to OTP plan query params #781

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions packages/core-utils/src/query-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,11 @@ export function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {
* @returns A fully formed query+variables ready to be sent to GraphQL backend
*/
export function generateOtp2Query(
{
arriveBy,
banned,
date,
from,
modes,
modeSettings,
numItineraries,
preferred,
time,
to,
unpreferred
}: OTPQueryParams,
otpQueryParams: OTPQueryParams,
planQuery = DefaultPlanQuery
): GraphQLQuery {
const { from, modeSettings, to, ...otherOtpQueryParams } = otpQueryParams;

// This extracts the values from the mode settings to key value pairs
const modeSettingValues = modeSettings.reduce((prev, cur) => {
if (cur.type === "SLIDER" && cur.inverseKey) {
Expand All @@ -247,26 +237,19 @@ export function generateOtp2Query(
const {
bikeReluctance,
carReluctance,
walkSpeed,
walkReluctance,
walkSpeed,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

wheelchair
} = modeSettingValues;

return {
query: print(planQuery),
variables: {
arriveBy,
banned,
...otherOtpQueryParams,
bikeReluctance,
carReluctance,
date,
fromPlace: `${from.name}::${from.lat},${from.lon}`,
modes,
numItineraries,
preferred,
time,
toPlace: `${to.name}::${to.lat},${to.lon}`,
unpreferred,
walkReluctance,
walkSpeed,
wheelchair
Expand Down
Loading