Skip to content

Commit

Permalink
Merge pull request #605 from ibi-group/allow-graphql-override
Browse files Browse the repository at this point in the history
feat(core-utils/query-gen): add support for overriding graphql query
  • Loading branch information
daniel-heppner-ibigroup committed Jun 22, 2023
2 parents 4a8f5ea + c9839bc commit aab251b
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions packages/core-utils/src/query-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TransportMode
} from "@opentripplanner/types";

import PlanQuery from "./planQuery.graphql";
import DefaultPlanQuery from "./planQuery.graphql";

type InputBanned = {
routes?: string;
Expand Down Expand Up @@ -201,18 +201,27 @@ export function generateCombinations(params: OTPQueryParams): OTPQueryParams[] {
.map(combo => ({ ...params, modes: combo }));
}

export function generateOtp2Query({
arriveBy,
banned,
date,
from,
modes,
modeSettings,
numItineraries,
preferred,
time,
to
}: OTPQueryParams): GraphQLQuery {
/**
* Generates a query for OTP GraphQL API based on parameters.
* @param param0 OTP2 Parameters for the query
* @param planQuery Override the default query for OTP
* @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
}: OTPQueryParams,
planQuery = DefaultPlanQuery
): GraphQLQuery {
// 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 @@ -230,7 +239,7 @@ export function generateOtp2Query({
} = modeSettingValues;

return {
query: print(PlanQuery),
query: print(planQuery),
variables: {
arriveBy,
banned,
Expand Down

0 comments on commit aab251b

Please sign in to comment.