Skip to content

Commit

Permalink
fix: drop pg function get_flow_schema in favor of simpler js data m…
Browse files Browse the repository at this point in the history
…unging (#2540)
  • Loading branch information
jessicamcinchak authored Dec 7, 2023
1 parent aa686fb commit d51efca
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 42 deletions.
4 changes: 1 addition & 3 deletions api.planx.uk/modules/flows/downloadSchema/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { ServerError } from "../../../errors";

interface DownloadFlowSchemaResponse {
message: string;
alteredNodes: Node[] | null;
description?: string;
}

export const downloadFlowSchema = z.object({
Expand All @@ -34,7 +32,7 @@ export const downloadFlowSchemaController: DownloadFlowSchemaController =
} catch (error) {
return next(
new ServerError({
message: `Failed to download flow schema: ${error}`,
message: `Failed to download schema for flow ${res.locals.parsedReq.params?.flowId}: ${error}`,
}),
);
}
Expand Down
39 changes: 16 additions & 23 deletions api.planx.uk/modules/flows/downloadSchema/service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { $public } from "../../../client";
import { gql } from "graphql-request";
import { getFlowData } from "../../../helpers";

interface FlowSchema {
node: string;
Expand All @@ -9,27 +8,21 @@ interface FlowSchema {
}

export const getFlowSchema = async (flowId: string) => {
const { flowSchema } = await $public.client.request<{
flowSchema: FlowSchema[];
}>(
gql`
query ($flow_id: String!) {
flowSchema: get_flow_schema(args: { published_flow_id: $flow_id }) {
node
type
text
planx_variable
}
}
`,
{ flow_id: flowId },
);
const flow = await getFlowData(flowId);

if (!flowSchema.length) {
throw Error(
"Can't find a schema for this flow. Make sure it's published or try a different flow id.",
);
}
const data: FlowSchema[] = [];
Object.entries(flow.data).map(([nodeId, nodeData]) =>
data.push({
node: nodeId,
type: nodeData?.type?.toString() || "_root",
text: nodeData.data?.text,
planx_variable:
nodeData.data?.fn ||
nodeData.data?.val ||
nodeData.data?.output ||
nodeData.data?.dataFieldBoundary,
}),
);

return flowSchema;
return data;
};
3 changes: 0 additions & 3 deletions hasura.planx.uk/metadata/functions.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- function:
schema: public
name: diff_latest_published_flow
- function:
schema: public
name: get_flow_schema
13 changes: 0 additions & 13 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,6 @@
- document_template
- flow_id
filter: {}
- table:
schema: public
name: flow_schemas
select_permissions:
- role: public
permission:
columns:
- flow_id
- node
- planx_variable
- text
- type
filter: {}
- table:
schema: public
name: flows
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- DROP FUNCTION public.get_flow_schema CASCADE;
-- DROP TABLE public.flow_schemas CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP FUNCTION public.get_flow_schema CASCADE;
DROP TABLE public.flow_schemas CASCADE;

0 comments on commit d51efca

Please sign in to comment.