From c07b377de15550f9d747070f390efb41b02574df Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 5 Jan 2022 23:24:31 +0300 Subject: [PATCH] feat: Create empty trigger step when the flow is created --- ...220105151725_remove_constraints_from_steps.ts | 16 ++++++++++++++++ .../backend/src/graphql/mutations/create-flow.ts | 6 ++++++ packages/backend/src/graphql/queries/get-flow.ts | 4 ++-- packages/backend/src/graphql/types/step.ts | 4 ++-- packages/backend/src/models/step.ts | 6 +++--- .../web/src/components/EditorLayout/index.tsx | 4 ++-- 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 packages/backend/src/db/migrations/20220105151725_remove_constraints_from_steps.ts diff --git a/packages/backend/src/db/migrations/20220105151725_remove_constraints_from_steps.ts b/packages/backend/src/db/migrations/20220105151725_remove_constraints_from_steps.ts new file mode 100644 index 00000000..369ccac7 --- /dev/null +++ b/packages/backend/src/db/migrations/20220105151725_remove_constraints_from_steps.ts @@ -0,0 +1,16 @@ +import { Knex } from "knex"; + +export async function up(knex: Knex): Promise { + return knex.schema.alterTable('steps', table => { + table.string('key').nullable().alter(); + table.string('app_key').nullable().alter(); + }) +} + +export async function down(knex: Knex): Promise { + return knex.schema.alterTable('steps', table => { + table.string('key').notNullable().alter(); + table.string('app_key').notNullable().alter(); + }) +} + diff --git a/packages/backend/src/graphql/mutations/create-flow.ts b/packages/backend/src/graphql/mutations/create-flow.ts index 35a53684..e1eb5eac 100644 --- a/packages/backend/src/graphql/mutations/create-flow.ts +++ b/packages/backend/src/graphql/mutations/create-flow.ts @@ -1,4 +1,5 @@ import Flow from '../../models/flow'; +import Step from '../../models/step'; import flowType from '../types/flow'; import RequestWithCurrentUser from '../../types/express/request-with-current-user'; @@ -7,6 +8,11 @@ const createFlowResolver = async (req: RequestWithCurrentUser) => { userId: req.currentUser.id }); + await Step.query().insert({ + flowId: flow.id, + type: 'trigger' + }) + return flow; } diff --git a/packages/backend/src/graphql/queries/get-flow.ts b/packages/backend/src/graphql/queries/get-flow.ts index 752edb8e..87f2b85c 100644 --- a/packages/backend/src/graphql/queries/get-flow.ts +++ b/packages/backend/src/graphql/queries/get-flow.ts @@ -1,4 +1,4 @@ -import { GraphQLNonNull, GraphQLString } from 'graphql'; +import { GraphQLNonNull, GraphQLInt } from 'graphql'; import Flow from '../../models/flow'; import RequestWithCurrentUser from '../../types/express/request-with-current-user'; import flowType from '../types/flow'; @@ -19,7 +19,7 @@ const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => { const getFlow = { type: flowType, args: { - id: { type: GraphQLNonNull(GraphQLString) }, + id: { type: GraphQLNonNull(GraphQLInt) }, }, resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getFlowResolver(params, req) } diff --git a/packages/backend/src/graphql/types/step.ts b/packages/backend/src/graphql/types/step.ts index 60e75628..cf4ee8a5 100644 --- a/packages/backend/src/graphql/types/step.ts +++ b/packages/backend/src/graphql/types/step.ts @@ -5,8 +5,8 @@ const stepType = new GraphQLObjectType({ name: 'Step', fields: { id: { type: GraphQLInt }, - key: { type: GraphQLNonNull(GraphQLString) }, - appKey: { type: GraphQLNonNull(GraphQLString) }, + key: { type: GraphQLString }, + appKey: { type: GraphQLString }, type: { type: new GraphQLEnumType({ name: 'StepEnumType', diff --git a/packages/backend/src/models/step.ts b/packages/backend/src/models/step.ts index 6f84400d..53fa39e6 100644 --- a/packages/backend/src/models/step.ts +++ b/packages/backend/src/models/step.ts @@ -10,8 +10,8 @@ enum StepEnumType { class Step extends Base { id!: number flowId!: number - key!: string - appKey!: string + key: string + appKey: string type!: StepEnumType connectionId!: number parameters: any @@ -20,7 +20,7 @@ class Step extends Base { static jsonSchema = { type: 'object', - required: ['key', 'appKey', 'type', 'connectionId'], + required: ['type'], properties: { id: { type: 'integer' }, diff --git a/packages/web/src/components/EditorLayout/index.tsx b/packages/web/src/components/EditorLayout/index.tsx index 35fdd1a0..4f680cbf 100644 --- a/packages/web/src/components/EditorLayout/index.tsx +++ b/packages/web/src/components/EditorLayout/index.tsx @@ -22,7 +22,7 @@ type EditorLayoutProps = { export default function EditorLayout(props: EditorLayoutProps) { const { flowId } = useParams(); const formatMessage = useFormatMessage(); - const { data } = useQuery(GET_FLOW, { variables: { id: flowId }}); + const { data } = useQuery(GET_FLOW, { variables: { id: Number(flowId) }}); const flow: Flow = data?.getFlow; return ( @@ -58,4 +58,4 @@ export default function EditorLayout(props: EditorLayoutProps) { ) -} \ No newline at end of file +}