diff --git a/packages/backend/src/graphql/mutations/create-auth-data.ts b/packages/backend/src/graphql/mutations/create-auth-data.ts index 59cd094f..fa770b6c 100644 --- a/packages/backend/src/graphql/mutations/create-auth-data.ts +++ b/packages/backend/src/graphql/mutations/create-auth-data.ts @@ -2,7 +2,9 @@ import Context from '../../types/express/context'; import App from '../../models/app'; type Params = { - id: string; + input: { + id: string; + }; }; const createAuthData = async ( @@ -13,7 +15,7 @@ const createAuthData = async ( const connection = await context.currentUser .$relatedQuery('connections') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/create-connection.ts b/packages/backend/src/graphql/mutations/create-connection.ts index 80d5fe73..6f752f98 100644 --- a/packages/backend/src/graphql/mutations/create-connection.ts +++ b/packages/backend/src/graphql/mutations/create-connection.ts @@ -3,21 +3,23 @@ import Context from '../../types/express/context'; import { IJSONObject } from '@automatisch/types'; type Params = { - key: string; - formattedData: IJSONObject; + input: { + key: string; + formattedData: IJSONObject; + }; }; const createConnection = async ( _parent: unknown, params: Params, context: Context ) => { - const app = App.findOneByKey(params.key); + const app = App.findOneByKey(params.input.key); const connection = await context.currentUser .$relatedQuery('connections') .insert({ - key: params.key, - formattedData: params.formattedData, + key: params.input.key, + formattedData: params.input.formattedData, }); return { diff --git a/packages/backend/src/graphql/mutations/delete-connection.ts b/packages/backend/src/graphql/mutations/delete-connection.ts index d5668886..47cb7797 100644 --- a/packages/backend/src/graphql/mutations/delete-connection.ts +++ b/packages/backend/src/graphql/mutations/delete-connection.ts @@ -1,7 +1,9 @@ import Context from '../../types/express/context'; type Params = { - id: string; + input: { + id: string; + }; }; const deleteConnection = async ( @@ -13,7 +15,7 @@ const deleteConnection = async ( .$relatedQuery('connections') .delete() .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/delete-flow.ts b/packages/backend/src/graphql/mutations/delete-flow.ts index 7b618279..9dcd5409 100644 --- a/packages/backend/src/graphql/mutations/delete-flow.ts +++ b/packages/backend/src/graphql/mutations/delete-flow.ts @@ -1,7 +1,9 @@ import Context from '../../types/express/context'; type Params = { - id: string; + input: { + id: string; + }; }; const deleteFlow = async ( @@ -13,7 +15,7 @@ const deleteFlow = async ( .$relatedQuery('flows') .delete() .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/delete-step.ts b/packages/backend/src/graphql/mutations/delete-step.ts index 0f89b0c6..705959f6 100644 --- a/packages/backend/src/graphql/mutations/delete-step.ts +++ b/packages/backend/src/graphql/mutations/delete-step.ts @@ -1,7 +1,9 @@ import Context from '../../types/express/context'; type Params = { - id: string; + input: { + id: string; + }; }; const deleteStep = async ( @@ -13,7 +15,7 @@ const deleteStep = async ( .$relatedQuery('steps') .withGraphFetched('flow') .findOne({ - 'steps.id': params.id, + 'steps.id': params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/execute-flow.ts b/packages/backend/src/graphql/mutations/execute-flow.ts index cc6196da..f9adaf49 100644 --- a/packages/backend/src/graphql/mutations/execute-flow.ts +++ b/packages/backend/src/graphql/mutations/execute-flow.ts @@ -4,7 +4,9 @@ import Processor from '../../services/processor'; import processorQueue from '../../queues/processor'; type Params = { - stepId: string; + input: { + stepId: string; + }; }; const executeFlow = async ( @@ -16,7 +18,7 @@ const executeFlow = async ( .$relatedQuery('steps') .withGraphFetched('connection') .findOne({ - 'steps.id': params.stepId, + 'steps.id': params.input.stepId, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/login.ts b/packages/backend/src/graphql/mutations/login.ts index b7e409f1..121f4269 100644 --- a/packages/backend/src/graphql/mutations/login.ts +++ b/packages/backend/src/graphql/mutations/login.ts @@ -3,18 +3,20 @@ import jwt from 'jsonwebtoken'; import appConfig from '../../config/app'; type Params = { - email: string; - password: string; + input: { + email: string; + password: string; + }; }; const TOKEN_EXPIRES_IN = '14d'; const login = async (_parent: unknown, params: Params) => { const user = await User.query().findOne({ - email: params.email, + email: params.input.email, }); - if (user && (await user.login(params.password))) { + if (user && (await user.login(params.input.password))) { const token = jwt.sign({ userId: user.id }, appConfig.appSecretKey, { expiresIn: TOKEN_EXPIRES_IN, }); diff --git a/packages/backend/src/graphql/mutations/reset-connection.ts b/packages/backend/src/graphql/mutations/reset-connection.ts index 826fd88f..06113673 100644 --- a/packages/backend/src/graphql/mutations/reset-connection.ts +++ b/packages/backend/src/graphql/mutations/reset-connection.ts @@ -1,7 +1,9 @@ import Context from '../../types/express/context'; type Params = { - id: string; + input: { + id: string; + }; }; const resetConnection = async ( @@ -12,7 +14,7 @@ const resetConnection = async ( let connection = await context.currentUser .$relatedQuery('connections') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/mutations/update-connection.ts b/packages/backend/src/graphql/mutations/update-connection.ts index 0e781d33..0df63204 100644 --- a/packages/backend/src/graphql/mutations/update-connection.ts +++ b/packages/backend/src/graphql/mutations/update-connection.ts @@ -2,8 +2,10 @@ import Context from '../../types/express/context'; import { IJSONObject } from '@automatisch/types'; type Params = { - id: string; - formattedData: IJSONObject; + input: { + id: string; + formattedData: IJSONObject; + }; }; const updateConnection = async ( @@ -14,14 +16,14 @@ const updateConnection = async ( let connection = await context.currentUser .$relatedQuery('connections') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); connection = await connection.$query().patchAndFetch({ formattedData: { ...connection.formattedData, - ...params.formattedData, + ...params.input.formattedData, }, }); diff --git a/packages/backend/src/graphql/mutations/update-flow-status.ts b/packages/backend/src/graphql/mutations/update-flow-status.ts index 50cf45ca..58027701 100644 --- a/packages/backend/src/graphql/mutations/update-flow-status.ts +++ b/packages/backend/src/graphql/mutations/update-flow-status.ts @@ -1,8 +1,10 @@ import Context from '../../types/express/context'; type Params = { - id: string; - active: boolean; + input: { + id: string; + active: boolean; + }; }; const updateFlowStatus = async ( @@ -13,16 +15,16 @@ const updateFlowStatus = async ( let flow = await context.currentUser .$relatedQuery('flows') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); - if (flow.active === params.active) { + if (flow.active === params.input.active) { return flow; } flow = await flow.$query().patchAndFetch({ - active: params.active, + active: params.input.active, }); return flow; diff --git a/packages/backend/src/graphql/mutations/update-flow.ts b/packages/backend/src/graphql/mutations/update-flow.ts index c1dfd51c..68866f78 100644 --- a/packages/backend/src/graphql/mutations/update-flow.ts +++ b/packages/backend/src/graphql/mutations/update-flow.ts @@ -1,8 +1,10 @@ import Context from '../../types/express/context'; type Params = { - id: string; - name: string; + input: { + id: string; + name: string; + }; }; const updateFlow = async ( @@ -13,12 +15,12 @@ const updateFlow = async ( let flow = await context.currentUser .$relatedQuery('flows') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); flow = await flow.$query().patchAndFetch({ - name: params.name, + name: params.input.name, }); return flow; diff --git a/packages/backend/src/graphql/mutations/update-user.ts b/packages/backend/src/graphql/mutations/update-user.ts index a16665c4..94515464 100644 --- a/packages/backend/src/graphql/mutations/update-user.ts +++ b/packages/backend/src/graphql/mutations/update-user.ts @@ -1,8 +1,10 @@ import Context from '../../types/express/context'; type Params = { - email: string; - password: string; + input: { + email: string; + password: string; + }; }; const updateUser = async ( @@ -11,8 +13,8 @@ const updateUser = async ( context: Context ) => { const user = await context.currentUser.$query().patchAndFetch({ - email: params.email, - password: params.password, + email: params.input.email, + password: params.input.password, }); return user; diff --git a/packages/backend/src/graphql/mutations/verify-connection.ts b/packages/backend/src/graphql/mutations/verify-connection.ts index 6a5a6c2d..0fca0bd7 100644 --- a/packages/backend/src/graphql/mutations/verify-connection.ts +++ b/packages/backend/src/graphql/mutations/verify-connection.ts @@ -2,7 +2,9 @@ import Context from '../../types/express/context'; import App from '../../models/app'; type Params = { - id: string; + input: { + id: string; + }; }; const verifyConnection = async ( @@ -13,7 +15,7 @@ const verifyConnection = async ( let connection = await context.currentUser .$relatedQuery('connections') .findOne({ - id: params.id, + id: params.input.id, }) .throwIfNotFound(); diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 6c977101..e9aae99a 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -10,25 +10,22 @@ type Query { } type Mutation { - createConnection( - key: AvailableAppsEnumType! - formattedData: JSONObject! - ): Connection - createAuthData(id: String!): AuthLink - updateConnection(id: String!, formattedData: JSONObject!): Connection - resetConnection(id: String!): Connection - verifyConnection(id: String!): Connection - deleteConnection(id: String!): Boolean - createFlow(input: FlowInput): Flow - updateFlow(id: String!, name: String!): Flow - updateFlowStatus(id: String!, active: Boolean!): Flow - executeFlow(stepId: String!): executeFlowType - deleteFlow(id: String!): Boolean - createStep(input: StepInput!): Step - updateStep(input: StepInput!): Step - deleteStep(id: String!): Step - updateUser(email: String, password: String): User - login(email: String!, password: String!): Auth + createConnection(input: CreateConnectionInput): Connection + createAuthData(input: CreateAuthDataInput): AuthLink + updateConnection(input: UpdateConnectionInput): Connection + resetConnection(input: ResetConnectionInput): Connection + verifyConnection(input: VerifyConnectionInput): Connection + deleteConnection(input: DeleteConnectionInput): Boolean + createFlow(input: CreateFlowInput): Flow + updateFlow(input: UpdateFlowInput): Flow + updateFlowStatus(input: UpdateFlowStatusInput): Flow + executeFlow(input: ExecuteFlowInput): executeFlowType + deleteFlow(input: DeleteFlowInput): Boolean + createStep(input: CreateStepInput): Step + updateStep(input: UpdateStepInput): Step + deleteStep(input: DeleteStepInput): Step + updateUser(input: UpdateUserInput): User + login(input: LoginInput): Auth } """ @@ -171,10 +168,76 @@ type Flow { steps: [Step] } -input FlowInput { +input CreateConnectionInput { + key: AvailableAppsEnumType! + formattedData: JSONObject! +} + +input CreateAuthDataInput { + id: String! +} + +input UpdateConnectionInput { + id: String! + formattedData: JSONObject! +} + +input ResetConnectionInput { + id: String! +} + +input VerifyConnectionInput { + id: String! +} + +input DeleteConnectionInput { + id: String! +} + +input CreateFlowInput { triggerAppKey: String } +input UpdateFlowInput { + id: String! + name: String! +} + +input UpdateFlowStatusInput { + id: String! + active: Boolean! +} + +input ExecuteFlowInput { + stepId: String! +} + +input DeleteFlowInput { + id: String! +} + +input CreateStepInput { + input: StepInput! +} + +input UpdateStepInput { + input: StepInput! +} + +input DeleteStepInput { + id: String! +} + +input UpdateUserInput { + email: String + password: String +} + +input LoginInput { + email: String! + password: String! +} + """ The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf). """