diff --git a/packages/backend/package.json b/packages/backend/package.json index eaa69b6e..cc9ddb78 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -18,6 +18,8 @@ }, "dependencies": { "@automatisch/web": "0.1.0", + "@graphql-tools/graphql-file-loader": "^7.3.4", + "@graphql-tools/load": "^7.5.2", "@octokit/oauth-methods": "^1.2.6", "ajv-formats": "^2.1.1", "axios": "0.24.0", @@ -34,6 +36,7 @@ "googleapis": "89.0.0", "graphql-middleware": "^6.1.15", "graphql-shield": "^7.5.0", + "graphql-tools": "^8.2.0", "graphql-type-json": "^0.3.2", "http-errors": "~1.6.3", "jsonwebtoken": "^8.5.1", diff --git a/packages/backend/src/graphql/graphql-schema.ts b/packages/backend/src/graphql/graphql-schema.ts deleted file mode 100644 index 182d1393..00000000 --- a/packages/backend/src/graphql/graphql-schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { GraphQLSchema } from 'graphql'; -import rootQuery from './root-query'; -import rootMutation from './root-mutation'; - -const graphQLSchema = new GraphQLSchema({ - query: rootQuery, - mutation: rootMutation -}); - -export default graphQLSchema; diff --git a/packages/backend/src/graphql/root-mutation.ts b/packages/backend/src/graphql/mutation-resolvers.ts similarity index 64% rename from packages/backend/src/graphql/root-mutation.ts rename to packages/backend/src/graphql/mutation-resolvers.ts index 9216406d..c7e36236 100644 --- a/packages/backend/src/graphql/root-mutation.ts +++ b/packages/backend/src/graphql/mutation-resolvers.ts @@ -1,4 +1,3 @@ -import { GraphQLObjectType } from 'graphql'; import createConnection from './mutations/create-connection'; import createAuthData from './mutations/create-auth-data'; import updateConnection from './mutations/update-connection'; @@ -10,29 +9,25 @@ import updateFlow from './mutations/update-flow'; import executeFlow from './mutations/execute-flow'; import deleteFlow from './mutations/delete-flow'; import createStep from './mutations/create-step'; -import deleteStep from './mutations/delete-step'; import updateStep from './mutations/update-step'; - +import deleteStep from './mutations/delete-step'; import login from './mutations/login'; -const rootMutation = new GraphQLObjectType({ - name: 'Mutation', - fields: { - createConnection, - createAuthData, - updateConnection, - resetConnection, - verifyConnection, - deleteConnection, - createFlow, - updateFlow, - deleteFlow, - createStep, - updateStep, - deleteStep, - executeFlow, - login, - }, -}); +const mutationResolvers = { + createConnection, + createAuthData, + updateConnection, + resetConnection, + verifyConnection, + deleteConnection, + createFlow, + updateFlow, + executeFlow, + deleteFlow, + createStep, + updateStep, + deleteStep, + login, +}; -export default rootMutation; +export default mutationResolvers; diff --git a/packages/backend/src/graphql/mutations/create-auth-data.ts b/packages/backend/src/graphql/mutations/create-auth-data.ts index 85f7b28d..59cd094f 100644 --- a/packages/backend/src/graphql/mutations/create-auth-data.ts +++ b/packages/backend/src/graphql/mutations/create-auth-data.ts @@ -1,17 +1,16 @@ -import { GraphQLNonNull, GraphQLString } from 'graphql'; -import authLinkType from '../types/auth-link'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; import App from '../../models/app'; type Params = { id: string; }; -const createAuthDataResolver = async ( +const createAuthData = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - const connection = await req.currentUser + const connection = await context.currentUser .$relatedQuery('connections') .findOne({ id: params.id, @@ -38,13 +37,4 @@ const createAuthDataResolver = async ( return authLink; }; -const createAuthData = { - type: authLinkType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - createAuthDataResolver(params, req), -}; - export default createAuthData; diff --git a/packages/backend/src/graphql/mutations/create-connection.ts b/packages/backend/src/graphql/mutations/create-connection.ts index bb46d56a..80d5fe73 100644 --- a/packages/backend/src/graphql/mutations/create-connection.ts +++ b/packages/backend/src/graphql/mutations/create-connection.ts @@ -1,25 +1,24 @@ -import { GraphQLNonNull } from 'graphql'; import App from '../../models/app'; -import connectionType from '../types/connection'; -import availableAppsEnumType from '../types/available-apps-enum-type'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import { GraphQLJSONObject } from 'graphql-type-json'; +import Context from '../../types/express/context'; import { IJSONObject } from '@automatisch/types'; type Params = { key: string; formattedData: IJSONObject; }; -const createConnectionResolver = async ( +const createConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { const app = App.findOneByKey(params.key); - const connection = await req.currentUser.$relatedQuery('connections').insert({ - key: params.key, - formattedData: params.formattedData, - }); + const connection = await context.currentUser + .$relatedQuery('connections') + .insert({ + key: params.key, + formattedData: params.formattedData, + }); return { ...connection, @@ -27,14 +26,4 @@ const createConnectionResolver = async ( }; }; -const createConnection = { - type: connectionType, - args: { - key: { type: GraphQLNonNull(availableAppsEnumType) }, - formattedData: { type: GraphQLNonNull(GraphQLJSONObject) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - createConnectionResolver(params, req), -}; - export default createConnection; diff --git a/packages/backend/src/graphql/mutations/create-flow.ts b/packages/backend/src/graphql/mutations/create-flow.ts index 81e89fc4..9ae925cc 100644 --- a/packages/backend/src/graphql/mutations/create-flow.ts +++ b/packages/backend/src/graphql/mutations/create-flow.ts @@ -1,6 +1,5 @@ import Step from '../../models/step'; -import flowType, { flowInputType } from '../types/flow'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { input: { @@ -8,13 +7,14 @@ type Params = { }; }; -const createFlowResolver = async ( +const createFlow = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { const appKey = params?.input?.triggerAppKey; - const flow = await req.currentUser.$relatedQuery('flows').insert({ + const flow = await context.currentUser.$relatedQuery('flows').insert({ name: 'Name your flow', }); @@ -28,13 +28,4 @@ const createFlowResolver = async ( return flow; }; -const createFlow = { - type: flowType, - args: { - input: { type: flowInputType }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - createFlowResolver(params, req), -}; - export default createFlow; diff --git a/packages/backend/src/graphql/mutations/create-step.ts b/packages/backend/src/graphql/mutations/create-step.ts index 8d02cb16..80ba0a1c 100644 --- a/packages/backend/src/graphql/mutations/create-step.ts +++ b/packages/backend/src/graphql/mutations/create-step.ts @@ -1,6 +1,4 @@ -import { GraphQLNonNull } from 'graphql'; -import stepType, { stepInputType } from '../types/step'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { input: { @@ -18,13 +16,14 @@ type Params = { }; }; -const createStepResolver = async ( +const createStep = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { const { input } = params; - const flow = await req.currentUser + const flow = await context.currentUser .$relatedQuery('flows') .findOne({ id: input.flow.id, @@ -61,13 +60,4 @@ const createStepResolver = async ( return step; }; -const createStep = { - type: stepType, - args: { - input: { type: new GraphQLNonNull(stepInputType) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - createStepResolver(params, req), -}; - export default createStep; diff --git a/packages/backend/src/graphql/mutations/delete-connection.ts b/packages/backend/src/graphql/mutations/delete-connection.ts index c056b4fe..d5668886 100644 --- a/packages/backend/src/graphql/mutations/delete-connection.ts +++ b/packages/backend/src/graphql/mutations/delete-connection.ts @@ -1,15 +1,15 @@ -import { GraphQLString, GraphQLNonNull, GraphQLBoolean } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { id: string; }; -const deleteConnectionResolver = async ( +const deleteConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - await req.currentUser + await context.currentUser .$relatedQuery('connections') .delete() .findOne({ @@ -20,13 +20,4 @@ const deleteConnectionResolver = async ( return; }; -const deleteConnection = { - type: GraphQLBoolean, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - deleteConnectionResolver(params, req), -}; - export default deleteConnection; diff --git a/packages/backend/src/graphql/mutations/delete-flow.ts b/packages/backend/src/graphql/mutations/delete-flow.ts index 1aa7e529..7b618279 100644 --- a/packages/backend/src/graphql/mutations/delete-flow.ts +++ b/packages/backend/src/graphql/mutations/delete-flow.ts @@ -1,15 +1,15 @@ -import { GraphQLString, GraphQLNonNull, GraphQLBoolean } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { id: string; }; -const deleteFlowResolver = async ( +const deleteFlow = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - await req.currentUser + await context.currentUser .$relatedQuery('flows') .delete() .findOne({ @@ -20,13 +20,4 @@ const deleteFlowResolver = async ( return; }; -const deleteFlow = { - type: GraphQLBoolean, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - deleteFlowResolver(params, req), -}; - export default deleteFlow; diff --git a/packages/backend/src/graphql/mutations/delete-step.ts b/packages/backend/src/graphql/mutations/delete-step.ts index 35199535..0f89b0c6 100644 --- a/packages/backend/src/graphql/mutations/delete-step.ts +++ b/packages/backend/src/graphql/mutations/delete-step.ts @@ -1,16 +1,15 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import stepType from '../types/step'; +import Context from '../../types/express/context'; type Params = { id: string; }; -const deleteStepResolver = async ( +const deleteStep = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - const step = await req.currentUser + const step = await context.currentUser .$relatedQuery('steps') .withGraphFetched('flow') .findOne({ @@ -40,13 +39,4 @@ const deleteStepResolver = async ( return step; }; -const deleteStep = { - type: stepType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - deleteStepResolver(params, req), -}; - export default deleteStep; diff --git a/packages/backend/src/graphql/mutations/execute-flow.ts b/packages/backend/src/graphql/mutations/execute-flow.ts index ee27c3f8..6db5292a 100644 --- a/packages/backend/src/graphql/mutations/execute-flow.ts +++ b/packages/backend/src/graphql/mutations/execute-flow.ts @@ -1,17 +1,17 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import executeFlowType from '../types/execute-flow'; +import Context from '../../types/express/context'; import Processor from '../../services/processor'; import processorQueue from '../../queues/processor'; type Params = { stepId: string; }; -const executeFlowResolver = async ( + +const executeFlow = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser -): Promise => { - const step = await req.currentUser + context: Context +) => { + const step = await context.currentUser .$relatedQuery('steps') .withGraphFetched('connection') .findOne({ @@ -35,13 +35,4 @@ const executeFlowResolver = async ( return { data, step }; }; -const executeFlow = { - type: executeFlowType, - args: { - stepId: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - executeFlowResolver(params, req), -}; - export default executeFlow; diff --git a/packages/backend/src/graphql/mutations/login.ts b/packages/backend/src/graphql/mutations/login.ts index 284b3abb..585fac20 100644 --- a/packages/backend/src/graphql/mutations/login.ts +++ b/packages/backend/src/graphql/mutations/login.ts @@ -1,6 +1,4 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; import User from '../../models/user'; -import authType from '../types/auth'; import jwt from 'jsonwebtoken'; import appConfig from '../../config/app'; @@ -9,7 +7,7 @@ type Params = { password: string; }; -const loginResolver = async (params: Params) => { +const login = async (_parent: unknown, params: Params) => { const user = await User.query().findOne({ email: params.email, }); @@ -23,13 +21,4 @@ const loginResolver = async (params: Params) => { throw new Error('User could not be found.'); }; -const login = { - type: authType, - args: { - email: { type: GraphQLNonNull(GraphQLString) }, - password: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: any) => loginResolver(params), -}; - export default login; diff --git a/packages/backend/src/graphql/mutations/reset-connection.ts b/packages/backend/src/graphql/mutations/reset-connection.ts index 2c52dbfb..826fd88f 100644 --- a/packages/backend/src/graphql/mutations/reset-connection.ts +++ b/packages/backend/src/graphql/mutations/reset-connection.ts @@ -1,16 +1,15 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import connectionType from '../types/connection'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { id: string; }; -const resetConnectionResolver = async ( +const resetConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - let connection = await req.currentUser + let connection = await context.currentUser .$relatedQuery('connections') .findOne({ id: params.id, @@ -24,13 +23,4 @@ const resetConnectionResolver = async ( return connection; }; -const resetConnection = { - type: connectionType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - resetConnectionResolver(params, req), -}; - export default resetConnection; diff --git a/packages/backend/src/graphql/mutations/update-connection.ts b/packages/backend/src/graphql/mutations/update-connection.ts index a2e769b5..0e781d33 100644 --- a/packages/backend/src/graphql/mutations/update-connection.ts +++ b/packages/backend/src/graphql/mutations/update-connection.ts @@ -1,7 +1,4 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import { GraphQLJSONObject } from 'graphql-type-json'; -import connectionType from '../types/connection'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; import { IJSONObject } from '@automatisch/types'; type Params = { @@ -9,11 +6,12 @@ type Params = { formattedData: IJSONObject; }; -const updateConnectionResolver = async ( +const updateConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - let connection = await req.currentUser + let connection = await context.currentUser .$relatedQuery('connections') .findOne({ id: params.id, @@ -30,14 +28,4 @@ const updateConnectionResolver = async ( return connection; }; -const updateConnection = { - type: connectionType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - formattedData: { type: GraphQLNonNull(GraphQLJSONObject) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - updateConnectionResolver(params, req), -}; - export default updateConnection; diff --git a/packages/backend/src/graphql/mutations/update-flow.ts b/packages/backend/src/graphql/mutations/update-flow.ts index a188c98e..f1deb5db 100644 --- a/packages/backend/src/graphql/mutations/update-flow.ts +++ b/packages/backend/src/graphql/mutations/update-flow.ts @@ -1,6 +1,4 @@ -import { GraphQLString, GraphQLNonNull, GraphQLBoolean } from 'graphql'; -import flowType from '../types/flow'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { id: string; @@ -8,11 +6,12 @@ type Params = { active: boolean; }; -const updateFlowResolver = async ( +const updateFlow = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - let flow = await req.currentUser + let flow = await context.currentUser .$relatedQuery('flows') .findOne({ id: params.id, @@ -24,15 +23,4 @@ const updateFlowResolver = async ( return flow; }; -const updateFlow = { - type: flowType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - name: { type: GraphQLNonNull(GraphQLString) }, - active: { type: GraphQLBoolean }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - updateFlowResolver(params, req), -}; - export default updateFlow; diff --git a/packages/backend/src/graphql/mutations/update-step.ts b/packages/backend/src/graphql/mutations/update-step.ts index 763003a3..45fd1295 100644 --- a/packages/backend/src/graphql/mutations/update-step.ts +++ b/packages/backend/src/graphql/mutations/update-step.ts @@ -1,7 +1,5 @@ -import { GraphQLNonNull } from 'graphql'; import Step from '../../models/step'; -import stepType, { stepInputType } from '../types/step'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; type Params = { input: { @@ -17,13 +15,15 @@ type Params = { }; }; }; -const updateStepResolver = async ( + +const updateStep = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { const { input } = params; - let step = await req.currentUser + let step = await context.currentUser .$relatedQuery('steps') .findOne({ 'steps.id': input.id, @@ -43,13 +43,4 @@ const updateStepResolver = async ( return step; }; -const updateStep = { - type: stepType, - args: { - input: { type: new GraphQLNonNull(stepInputType) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - updateStepResolver(params, req), -}; - export default updateStep; diff --git a/packages/backend/src/graphql/mutations/verify-connection.ts b/packages/backend/src/graphql/mutations/verify-connection.ts index 118f6bdc..6a5a6c2d 100644 --- a/packages/backend/src/graphql/mutations/verify-connection.ts +++ b/packages/backend/src/graphql/mutations/verify-connection.ts @@ -1,17 +1,16 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import connectionType from '../types/connection'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; +import Context from '../../types/express/context'; import App from '../../models/app'; type Params = { id: string; }; -const verifyConnectionResolver = async ( +const verifyConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - let connection = await req.currentUser + let connection = await context.currentUser .$relatedQuery('connections') .findOne({ id: params.id, @@ -36,13 +35,4 @@ const verifyConnectionResolver = async ( return connection; }; -const verifyConnection = { - type: connectionType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - verifyConnectionResolver(params, req), -}; - export default verifyConnection; diff --git a/packages/backend/src/graphql/queries/get-app-connections.ts b/packages/backend/src/graphql/queries/get-app-connections.ts index a845fff3..b8cd00b8 100644 --- a/packages/backend/src/graphql/queries/get-app-connections.ts +++ b/packages/backend/src/graphql/queries/get-app-connections.ts @@ -1,22 +1,22 @@ -import { GraphQLList, GraphQLNonNull } from 'graphql'; import App from '../../models/app'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import connectionType from '../types/connection'; -import availableAppsEnumType from '../types/available-apps-enum-type'; +import Context from '../../types/express/context'; type Params = { key: string; }; -const getAppConnectionsResolver = async ( +const getAppConnections = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { const app = App.findOneByKey(params.key); - const connections = await req.currentUser.$relatedQuery('connections').where({ - key: params.key, - }); + const connections = await context.currentUser + .$relatedQuery('connections') + .where({ + key: params.key, + }); return connections.map((connection) => ({ ...connection, @@ -24,13 +24,4 @@ const getAppConnectionsResolver = async ( })); }; -const getAppConnections = { - type: GraphQLList(connectionType), - args: { - key: { type: GraphQLNonNull(availableAppsEnumType) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - getAppConnectionsResolver(params, req), -}; - export default getAppConnections; diff --git a/packages/backend/src/graphql/queries/get-app.ts b/packages/backend/src/graphql/queries/get-app.ts index 805411e2..7f5edc93 100644 --- a/packages/backend/src/graphql/queries/get-app.ts +++ b/packages/backend/src/graphql/queries/get-app.ts @@ -1,18 +1,15 @@ -import { GraphQLNonNull } from 'graphql'; import App from '../../models/app'; -import appType from '../types/app'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import availableAppsEnumType from '../types/available-apps-enum-type'; +import Context from '../../types/express/context'; type Params = { key: string; }; -const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => { +const getApp = async (_parent: unknown, params: Params, context: Context) => { const app = App.findOneByKey(params.key); - if (req.currentUser) { - const connections = await req.currentUser + if (context.currentUser) { + const connections = await context.currentUser .$relatedQuery('connections') .where({ key: params.key, @@ -27,13 +24,4 @@ const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => { return app; }; -const getApp = { - type: appType, - args: { - key: { type: GraphQLNonNull(availableAppsEnumType) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - getAppResolver(params, req), -}; - export default getApp; diff --git a/packages/backend/src/graphql/queries/get-apps.ts b/packages/backend/src/graphql/queries/get-apps.ts index 5c818469..351fc394 100644 --- a/packages/backend/src/graphql/queries/get-apps.ts +++ b/packages/backend/src/graphql/queries/get-apps.ts @@ -1,29 +1,19 @@ -import { GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql'; -import appType from '../types/app'; import App from '../../models/app'; +import { IApp } from '@automatisch/types'; type Params = { name: string; onlyWithTriggers: boolean; }; -const getAppsResolver = (params: Params) => { +const getApps = (_parent: unknown, params: Params) => { const apps = App.findAll(params.name); if (params.onlyWithTriggers) { - return apps.filter((app: any) => app.triggers?.length); + return apps.filter((app: IApp) => app.triggers?.length); } return apps; }; -const getApps = { - type: GraphQLList(appType), - args: { - name: { type: GraphQLString }, - onlyWithTriggers: { type: GraphQLBoolean }, - }, - resolve: (_: any, params: Params) => getAppsResolver(params), -}; - export default getApps; diff --git a/packages/backend/src/graphql/queries/get-connected-apps.ts b/packages/backend/src/graphql/queries/get-connected-apps.ts index feea647a..2e1615ab 100644 --- a/packages/backend/src/graphql/queries/get-connected-apps.ts +++ b/packages/backend/src/graphql/queries/get-connected-apps.ts @@ -1,19 +1,19 @@ -import { GraphQLList, GraphQLString } from 'graphql'; import App from '../../models/app'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import appType from '../types/app'; +import Context from '../../types/express/context'; +import { IApp, IConnection } from '@automatisch/types'; type Params = { name: string; }; -const getConnectedAppsResolver = async ( +const getConnectedApps = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { let apps = App.findAll(params.name); - const connections = await req.currentUser + const connections = await context.currentUser .$relatedQuery('connections') .select('connections.key') .count('connections.id as count') @@ -23,10 +23,10 @@ const getConnectedAppsResolver = async ( const connectionKeys = connections.map((connection) => connection.key); apps = apps - .filter((app: any) => connectionKeys.includes(app.key)) - .map((app: any) => { + .filter((app: IApp) => connectionKeys.includes(app.key)) + .map((app: IApp) => { const connection = connections.find( - (connection: any) => connection.key === app.key + (connection: IConnection) => connection.key === app.key ); app.connectionCount = connection.count; @@ -36,13 +36,4 @@ const getConnectedAppsResolver = async ( return apps; }; -const getConnectedApps = { - type: GraphQLList(appType), - args: { - name: { type: GraphQLString }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - getConnectedAppsResolver(params, req), -}; - export default getConnectedApps; diff --git a/packages/backend/src/graphql/queries/get-flow.ts b/packages/backend/src/graphql/queries/get-flow.ts index 64735716..b7d39852 100644 --- a/packages/backend/src/graphql/queries/get-flow.ts +++ b/packages/backend/src/graphql/queries/get-flow.ts @@ -1,13 +1,11 @@ -import { GraphQLNonNull, GraphQLString } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import flowType from '../types/flow'; +import Context from '../../types/express/context'; type Params = { id: string; }; -const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => { - const flow = await req.currentUser +const getFlow = async (_parent: unknown, params: Params, context: Context) => { + const flow = await context.currentUser .$relatedQuery('flows') .withGraphJoined('[steps.[connection]]') .orderBy('steps.position', 'asc') @@ -17,13 +15,4 @@ const getFlowResolver = async (params: Params, req: RequestWithCurrentUser) => { return flow; }; -const getFlow = { - type: flowType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - getFlowResolver(params, req), -}; - export default getFlow; diff --git a/packages/backend/src/graphql/queries/get-flows.ts b/packages/backend/src/graphql/queries/get-flows.ts index cd6ce182..ba8819ba 100644 --- a/packages/backend/src/graphql/queries/get-flows.ts +++ b/packages/backend/src/graphql/queries/get-flows.ts @@ -1,21 +1,15 @@ -import { GraphQLList } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import flowType from '../types/flow'; +import Context from '../../types/express/context'; -const getFlowsResolver = async ( - req: RequestWithCurrentUser -): Promise => { - const flows = await req.currentUser +const getFlows = async ( + _parent: unknown, + _params: unknown, + context: Context +) => { + const flows = await context.currentUser .$relatedQuery('flows') .withGraphJoined('[steps.[connection]]'); return flows; }; -const getFlows = { - type: GraphQLList(flowType), - resolve: (_: any, _params: any, req: RequestWithCurrentUser) => - getFlowsResolver(req), -}; - export default getFlows; diff --git a/packages/backend/src/graphql/queries/get-step-with-test-executions.ts b/packages/backend/src/graphql/queries/get-step-with-test-executions.ts index aabd869c..9030195b 100644 --- a/packages/backend/src/graphql/queries/get-step-with-test-executions.ts +++ b/packages/backend/src/graphql/queries/get-step-with-test-executions.ts @@ -1,21 +1,20 @@ -import { GraphQLNonNull, GraphQLString, GraphQLList } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import stepType from '../types/step'; +import Context from '../../types/express/context'; type Params = { stepId: string; }; -const getStepWithTestExecutionsResolver = async ( +const getStepWithTestExecutions = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - const step = await req.currentUser + const step = await context.currentUser .$relatedQuery('steps') .findOne({ 'steps.id': params.stepId }) .throwIfNotFound(); - const previousStepsWithCurrentStep = await req.currentUser + const previousStepsWithCurrentStep = await context.currentUser .$relatedQuery('steps') .withGraphJoined('executionSteps') .where('flow_id', '=', step.flowId) @@ -29,13 +28,4 @@ const getStepWithTestExecutionsResolver = async ( return previousStepsWithCurrentStep; }; -const getStepWithTestExecutions = { - type: GraphQLList(stepType), - args: { - stepId: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - getStepWithTestExecutionsResolver(params, req), -}; - export default getStepWithTestExecutions; diff --git a/packages/backend/src/graphql/queries/test-connection.ts b/packages/backend/src/graphql/queries/test-connection.ts index 6c991a82..efa69792 100644 --- a/packages/backend/src/graphql/queries/test-connection.ts +++ b/packages/backend/src/graphql/queries/test-connection.ts @@ -1,17 +1,17 @@ -import { GraphQLString, GraphQLNonNull } from 'graphql'; -import RequestWithCurrentUser from '../../types/express/request-with-current-user'; -import connectionType from '../types/connection'; +import Context from '../../types/express/context'; import App from '../../models/app'; type Params = { id: string; data: object; }; -const testConnectionResolver = async ( + +const testConnection = async ( + _parent: unknown, params: Params, - req: RequestWithCurrentUser + context: Context ) => { - let connection = await req.currentUser + let connection = await context.currentUser .$relatedQuery('connections') .findOne({ id: params.id, @@ -33,13 +33,4 @@ const testConnectionResolver = async ( return connection; }; -const testConnection = { - type: connectionType, - args: { - id: { type: GraphQLNonNull(GraphQLString) }, - }, - resolve: (_: any, params: Params, req: RequestWithCurrentUser) => - testConnectionResolver(params, req), -}; - export default testConnection; diff --git a/packages/backend/src/graphql/root-query.ts b/packages/backend/src/graphql/query-resolvers.ts similarity index 59% rename from packages/backend/src/graphql/root-query.ts rename to packages/backend/src/graphql/query-resolvers.ts index 484fdcd1..8b91ce15 100644 --- a/packages/backend/src/graphql/root-query.ts +++ b/packages/backend/src/graphql/query-resolvers.ts @@ -1,4 +1,3 @@ -import { GraphQLObjectType } from 'graphql'; import getApps from './queries/get-apps'; import getApp from './queries/get-app'; import getConnectedApps from './queries/get-connected-apps'; @@ -8,18 +7,15 @@ import getFlow from './queries/get-flow'; import getFlows from './queries/get-flows'; import getStepWithTestExecutions from './queries/get-step-with-test-executions'; -const rootQuery = new GraphQLObjectType({ - name: 'Query', - fields: { - getApps, - getApp, - getConnectedApps, - getAppConnections, - testConnection, - getFlow, - getFlows, - getStepWithTestExecutions, - }, -}); +const queryResolvers = { + getApps, + getApp, + getConnectedApps, + getAppConnections, + testConnection, + getFlow, + getFlows, + getStepWithTestExecutions, +}; -export default rootQuery; +export default queryResolvers; diff --git a/packages/backend/src/graphql/resolvers.ts b/packages/backend/src/graphql/resolvers.ts new file mode 100644 index 00000000..8087332f --- /dev/null +++ b/packages/backend/src/graphql/resolvers.ts @@ -0,0 +1,9 @@ +import mutationResolvers from './mutation-resolvers'; +import queryResolvers from './query-resolvers'; + +const resolvers = { + Query: queryResolvers, + Mutation: mutationResolvers, +}; + +export default resolvers; diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql new file mode 100644 index 00000000..09329308 --- /dev/null +++ b/packages/backend/src/graphql/schema.graphql @@ -0,0 +1,272 @@ +type Query { + getApps(name: String, onlyWithTriggers: Boolean): [App] + getApp(key: AvailableAppsEnumType!): App + getConnectedApps(name: String): [App] + getAppConnections(key: AvailableAppsEnumType!): [Connection] + testConnection(id: String!): Connection + getFlow(id: String!): Flow + getFlows: [Flow] + getStepWithTestExecutions(stepId: String!): [Step] +} + +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!, active: Boolean): Flow + deleteFlow(id: String!): Boolean + createStep(input: StepInput!): Step + updateStep(input: StepInput!): Step + deleteStep(id: String!): Step + executeFlow(stepId: String!): executeFlowType + login(email: String!, password: String!): Auth +} + +""" +Exposes a URL that specifies the behaviour of this scalar. +""" +directive @specifiedBy( + """ + The URL that specifies the behaviour of this scalar. + """ + url: String! +) on SCALAR + +type Action { + name: String + key: String + description: String + subSteps: [ActionSubStep] +} + +type ActionSubStep { + key: String + name: String + arguments: [ActionSubStepArgument] +} + +type ActionSubStepArgument { + label: String + key: String + type: String + description: String + required: Boolean + variables: Boolean +} + +type App { + name: String + key: String + connectionCount: Int + iconUrl: String + docUrl: String + primaryColor: String + fields: [Field] + authenticationSteps: [AuthenticationStep] + reconnectionSteps: [ReconnectionStep] + triggers: [Trigger] + actions: [Action] + connections: [Connection] +} + +enum ArgumentEnumType { + integer + string +} + +type Auth { + user: User + token: String +} + +type AuthenticationStep { + step: Int + type: String + name: String + arguments: [AuthenticationStepArgument] +} + +type AuthenticationStepArgument { + name: String + value: String + type: ArgumentEnumType + properties: [AuthenticationStepProperty] +} + +type AuthenticationStepProperty { + name: String + value: String +} + +type AuthLink { + url: String +} + +enum AvailableAppsEnumType { + discord + firebase + flickr + github + postgresql + smtp + twilio + twitch + twitter + typeform +} + +type Connection { + id: String + key: String + formattedData: ConnectionData + verified: Boolean + app: App + createdAt: String +} + +type ConnectionData { + screenName: String +} + +type executeFlowType { + data: JSONObject + step: Step +} + +type ExecutionStep { + id: String + executionId: String + stepId: String + status: String + dataIn: JSONObject + dataOut: JSONObject +} + +type Field { + key: String + label: String + type: String + required: Boolean + readOnly: Boolean + value: String + placeholder: String + description: String + docUrl: String + clickToCopy: Boolean +} + +type Flow { + id: String + name: String + active: Boolean + steps: [Step] +} + +input FlowInput { + triggerAppKey: 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). +""" +scalar JSONObject + +input PreviousStepInput { + id: String +} + +type ReconnectionStep { + step: Int + type: String + name: String + arguments: [ReconnectionStepArgument] +} + +type ReconnectionStepArgument { + name: String + value: String + type: ArgumentEnumType + properties: [ReconnectionStepProperty] +} + +type ReconnectionStepProperty { + name: String + value: String +} + +type Step { + id: String + previousStepId: String + key: String + appKey: String + type: StepEnumType + parameters: JSONObject + connection: Connection + flow: Flow + position: Int + status: String + executionSteps: [ExecutionStep] +} + +input StepConnectionInput { + id: String +} + +enum StepEnumType { + trigger + action +} + +input StepFlowInput { + id: String +} + +input StepInput { + id: String + previousStepId: String + key: String + appKey: String + connection: StepConnectionInput + flow: StepFlowInput + parameters: JSONObject + previousStep: PreviousStepInput +} + +type Trigger { + name: String + key: String + description: String + subSteps: [TriggerSubStep] +} + +type TriggerSubStep { + key: String + name: String + arguments: [TriggerSubStepArgument] +} + +type TriggerSubStepArgument { + label: String + key: String + type: String + required: Boolean +} + +type User { + id: String + email: String + createdAt: String + updatedAt: String +} + +schema { + query: Query + mutation: Mutation +} diff --git a/packages/backend/src/graphql/types/action.ts b/packages/backend/src/graphql/types/action.ts deleted file mode 100644 index 350c6ba3..00000000 --- a/packages/backend/src/graphql/types/action.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql'; - -const actionType = new GraphQLObjectType({ - name: 'Action', - fields: { - name: { type: GraphQLString }, - key: { type: GraphQLString }, - description: { type: GraphQLString }, - subSteps: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'ActionSubStep', - fields: { - key: { type: GraphQLString }, - name: { type: GraphQLString }, - arguments: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'ActionSubStepArgument', - fields: { - label: { type: GraphQLString }, - key: { type: GraphQLString }, - type: { type: GraphQLString }, - description: { type: GraphQLString }, - required: { type: GraphQLBoolean }, - variables: { type: GraphQLBoolean } - } - }) - ) - }, - } - }), - ) - } - } -}) - -export default actionType; diff --git a/packages/backend/src/graphql/types/app.ts b/packages/backend/src/graphql/types/app.ts deleted file mode 100644 index ea50d753..00000000 --- a/packages/backend/src/graphql/types/app.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLInt } from 'graphql'; -import fieldType from './field'; -import authenticationStepType from './authentication-step'; -import reconnectionStepType from './reconnection-step'; -import triggerType from './trigger'; -import actionType from './action'; - -const appType = new GraphQLObjectType({ - name: 'App', - fields: () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const connectionType = require('./connection').default; - - return { - name: { type: GraphQLString }, - key: { type: GraphQLString }, - connectionCount: { type: GraphQLInt }, - iconUrl: { type: GraphQLString }, - docUrl: { type: GraphQLString }, - primaryColor: { type: GraphQLString }, - fields: { type: GraphQLList(fieldType) }, - authenticationSteps: { type: GraphQLList(authenticationStepType) }, - reconnectionSteps: { type: GraphQLList(reconnectionStepType) }, - triggers: { type: GraphQLList(triggerType) }, - actions: { type: GraphQLList(actionType) }, - connections: { type: GraphQLList(connectionType) }, - } - } -}); - -export default appType; diff --git a/packages/backend/src/graphql/types/argument-enum-type.ts b/packages/backend/src/graphql/types/argument-enum-type.ts deleted file mode 100644 index a81a08eb..00000000 --- a/packages/backend/src/graphql/types/argument-enum-type.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GraphQLEnumType } from 'graphql'; - -const argumentEnumValues = { - integer: { value: 'integer' }, - string: { value: 'string' } -} - -const ArgumentEnumType = new GraphQLEnumType({ - name: 'ArgumentEnumType', - values: argumentEnumValues -}) - -export default ArgumentEnumType; diff --git a/packages/backend/src/graphql/types/auth-link.ts b/packages/backend/src/graphql/types/auth-link.ts deleted file mode 100644 index 32eec18c..00000000 --- a/packages/backend/src/graphql/types/auth-link.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { GraphQLObjectType, GraphQLString } from 'graphql'; - -const authLinkType = new GraphQLObjectType({ - name: 'AuthLink', - fields: { - url: { type: GraphQLString } - } -}) - -export default authLinkType; diff --git a/packages/backend/src/graphql/types/auth.ts b/packages/backend/src/graphql/types/auth.ts deleted file mode 100644 index 4d76faac..00000000 --- a/packages/backend/src/graphql/types/auth.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { GraphQLObjectType, GraphQLString } from 'graphql'; -import UserType from './user'; - -const authType = new GraphQLObjectType({ - name: 'Auth', - fields: { - user: { type: UserType }, - token: { type: GraphQLString }, - }, -}); - -export default authType; diff --git a/packages/backend/src/graphql/types/authentication-step.ts b/packages/backend/src/graphql/types/authentication-step.ts deleted file mode 100644 index 00fb0f07..00000000 --- a/packages/backend/src/graphql/types/authentication-step.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLInt } from 'graphql'; -import ArgumentEnumType from './argument-enum-type'; - -const authenticationStepType = new GraphQLObjectType({ - name: 'AuthenticationStep', - fields: { - step: { type: GraphQLInt }, - type: { type: GraphQLString }, - name: { type: GraphQLString }, - arguments: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'AuthenticationStepArgument', - fields: { - name: { type: GraphQLString }, - value: { type: GraphQLString }, - type: { type: ArgumentEnumType }, - properties: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'AuthenticationStepProperty', - fields: { - name: { type: GraphQLString }, - value: { type: GraphQLString } - } - }) - ) - }, - } - }), - ) - } - } -}) - -export default authenticationStepType; diff --git a/packages/backend/src/graphql/types/available-apps-enum-type.ts b/packages/backend/src/graphql/types/available-apps-enum-type.ts deleted file mode 100644 index a4d41361..00000000 --- a/packages/backend/src/graphql/types/available-apps-enum-type.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { IApp } from '@automatisch/types'; -import { GraphQLEnumType } from 'graphql'; -import App from '../../models/app'; - -const apps = App.findAll(); -const availableAppEnumValues: any = {} - -apps.forEach((app: IApp) => { - availableAppEnumValues[app.key] = { value: app.key } -}) - -const availableAppsEnumType = new GraphQLEnumType({ - name: 'AvailableAppsEnumType', - values: availableAppEnumValues -}) - -export default availableAppsEnumType; diff --git a/packages/backend/src/graphql/types/connection-data.ts b/packages/backend/src/graphql/types/connection-data.ts deleted file mode 100644 index d42d637c..00000000 --- a/packages/backend/src/graphql/types/connection-data.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { GraphQLString, GraphQLObjectType } from 'graphql'; - -const connectionDataType = new GraphQLObjectType({ - name: 'ConnectionData', - fields: { - screenName: { type: GraphQLString }, - } -}) - -export default connectionDataType; diff --git a/packages/backend/src/graphql/types/connection.ts b/packages/backend/src/graphql/types/connection.ts deleted file mode 100644 index 9567176a..00000000 --- a/packages/backend/src/graphql/types/connection.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql'; -import connectionDataType from './connection-data'; - -const connectionType = new GraphQLObjectType({ - name: 'Connection', - fields: () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const appType = require('./app').default; - - return { - id: { type: GraphQLString }, - key: { type: GraphQLString }, - formattedData: { type: connectionDataType }, - verified: { type: GraphQLBoolean }, - app: { type: appType }, - createdAt: { type: GraphQLString }, - }; - }, -}); - -export default connectionType; diff --git a/packages/backend/src/graphql/types/execute-flow.ts b/packages/backend/src/graphql/types/execute-flow.ts deleted file mode 100644 index a0ee65b1..00000000 --- a/packages/backend/src/graphql/types/execute-flow.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GraphQLJSONObject } from 'graphql-type-json'; -import { GraphQLObjectType } from 'graphql'; -import stepType from './step'; - -const executeFlowType = new GraphQLObjectType({ - name: 'executeFlowType', - fields: { - data: { type: GraphQLJSONObject }, - step: { type: stepType }, - }, -}); - -export default executeFlowType; diff --git a/packages/backend/src/graphql/types/execution-step.ts b/packages/backend/src/graphql/types/execution-step.ts deleted file mode 100644 index f48d306d..00000000 --- a/packages/backend/src/graphql/types/execution-step.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLBoolean } from 'graphql'; -import { GraphQLJSONObject } from 'graphql-type-json'; - -const executionStepType = new GraphQLObjectType({ - name: 'ExecutionStep', - fields: { - id: { type: GraphQLString }, - executionId: { type: GraphQLString }, - stepId: { type: GraphQLString }, - status: { type: GraphQLString }, - dataIn: { type: GraphQLJSONObject }, - dataOut: { type: GraphQLJSONObject }, - }, -}); - -export default executionStepType; diff --git a/packages/backend/src/graphql/types/field.ts b/packages/backend/src/graphql/types/field.ts deleted file mode 100644 index b8dbbe46..00000000 --- a/packages/backend/src/graphql/types/field.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLBoolean} from 'graphql'; - -const fieldType = new GraphQLObjectType({ - name: 'Field', - fields: { - key: { type: GraphQLString }, - label: { type: GraphQLString }, - type: { type: GraphQLString }, - required: { type: GraphQLBoolean}, - readOnly: { type: GraphQLBoolean}, - value: { type: GraphQLString}, - placeholder: { type: GraphQLString}, - description: { type: GraphQLString}, - docUrl: { type: GraphQLString}, - clickToCopy: { type: GraphQLBoolean}, - } -}) - -export default fieldType; diff --git a/packages/backend/src/graphql/types/flow.ts b/packages/backend/src/graphql/types/flow.ts deleted file mode 100644 index 50170145..00000000 --- a/packages/backend/src/graphql/types/flow.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - GraphQLList, - GraphQLObjectType, - GraphQLInputObjectType, - GraphQLString, - GraphQLBoolean, -} from 'graphql'; - -const flowType = new GraphQLObjectType({ - name: 'Flow', - fields: () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const StepType = require('./step').default; - - return { - id: { type: GraphQLString }, - name: { type: GraphQLString }, - active: { type: GraphQLBoolean }, - steps: { - type: GraphQLList(StepType), - }, - }; - }, -}); - -export const flowInputType = new GraphQLInputObjectType({ - name: 'FlowInput', - fields: { - triggerAppKey: { type: GraphQLString }, - }, -}); - -export default flowType; diff --git a/packages/backend/src/graphql/types/reconnection-step.ts b/packages/backend/src/graphql/types/reconnection-step.ts deleted file mode 100644 index 534a24e6..00000000 --- a/packages/backend/src/graphql/types/reconnection-step.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLInt } from 'graphql'; -import ArgumentEnumType from './argument-enum-type'; - -const reconnectionStepType = new GraphQLObjectType({ - name: 'ReconnectionStep', - fields: { - step: { type: GraphQLInt }, - type: { type: GraphQLString }, - name: { type: GraphQLString }, - arguments: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'ReconnectionStepArgument', - fields: { - name: { type: GraphQLString }, - value: { type: GraphQLString }, - type: { type: ArgumentEnumType }, - properties: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'ReconnectionStepProperty', - fields: { - name: { type: GraphQLString }, - value: { type: GraphQLString } - } - }) - ) - }, - } - }), - ) - } - } -}) - -export default reconnectionStepType; diff --git a/packages/backend/src/graphql/types/step.ts b/packages/backend/src/graphql/types/step.ts deleted file mode 100644 index 76460805..00000000 --- a/packages/backend/src/graphql/types/step.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { - GraphQLObjectType, - GraphQLString, - GraphQLEnumType, - GraphQLInt, - GraphQLInputObjectType, - GraphQLList, -} from 'graphql'; -import { GraphQLJSONObject } from 'graphql-type-json'; -import ConnectionType from './connection'; -import ExecutionStepType from './execution-step'; - -const stepType = new GraphQLObjectType({ - name: 'Step', - fields: () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const FlowType = require('./flow').default; - - return { - id: { type: GraphQLString }, - previousStepId: { type: GraphQLString }, - key: { type: GraphQLString }, - appKey: { type: GraphQLString }, - type: { - type: new GraphQLEnumType({ - name: 'StepEnumType', - values: { - trigger: { value: 'trigger' }, - action: { value: 'action' }, - }, - }), - }, - parameters: { type: GraphQLJSONObject }, - connection: { type: ConnectionType }, - flow: { type: FlowType }, - position: { type: GraphQLInt }, - status: { type: GraphQLString }, - executionSteps: { - type: GraphQLList(ExecutionStepType), - }, - }; - }, -}); - -export const stepInputType = new GraphQLInputObjectType({ - name: 'StepInput', - fields: { - id: { type: GraphQLString }, - previousStepId: { type: GraphQLString }, - key: { type: GraphQLString }, - appKey: { type: GraphQLString }, - connection: { - type: new GraphQLInputObjectType({ - name: 'StepConnectionInput', - fields: { - id: { type: GraphQLString }, - }, - }), - }, - flow: { - type: new GraphQLInputObjectType({ - name: 'StepFlowInput', - fields: { - id: { type: GraphQLString }, - }, - }), - }, - parameters: { type: GraphQLJSONObject }, - previousStep: { - type: new GraphQLInputObjectType({ - name: 'PreviousStepInput', - fields: { - id: { type: GraphQLString }, - }, - }), - }, - }, -}); - -export default stepType; diff --git a/packages/backend/src/graphql/types/trigger.ts b/packages/backend/src/graphql/types/trigger.ts deleted file mode 100644 index 1ddef940..00000000 --- a/packages/backend/src/graphql/types/trigger.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean } from 'graphql'; - -const triggerType = new GraphQLObjectType({ - name: 'Trigger', - fields: { - name: { type: GraphQLString }, - key: { type: GraphQLString }, - description: { type: GraphQLString }, - subSteps: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'TriggerSubStep', - fields: { - key: { type: GraphQLString }, - name: { type: GraphQLString }, - arguments: { - type: GraphQLList( - new GraphQLObjectType({ - name: 'TriggerSubStepArgument', - fields: { - label: { type: GraphQLString }, - key: { type: GraphQLString }, - type: { type: GraphQLString }, - required: { type: GraphQLBoolean } - } - }) - ) - }, - } - }), - ) - } - } -}) - -export default triggerType; diff --git a/packages/backend/src/graphql/types/user.ts b/packages/backend/src/graphql/types/user.ts deleted file mode 100644 index c03104c4..00000000 --- a/packages/backend/src/graphql/types/user.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { GraphQLObjectType, GraphQLString } from 'graphql'; - -const userType = new GraphQLObjectType({ - name: 'User', - fields: { - id: { type: GraphQLString }, - email: { type: GraphQLString }, - createdAt: { type: GraphQLString }, - updatedAt: { type: GraphQLString }, - }, -}); - -export default userType; diff --git a/packages/backend/src/helpers/graphql-instance.ts b/packages/backend/src/helpers/graphql-instance.ts index 00ec68f9..aa55fe71 100644 --- a/packages/backend/src/helpers/graphql-instance.ts +++ b/packages/backend/src/helpers/graphql-instance.ts @@ -1,11 +1,24 @@ import { graphqlHTTP } from 'express-graphql'; -import graphQLSchema from '../graphql/graphql-schema'; import logger from '../helpers/logger'; import { applyMiddleware } from 'graphql-middleware'; import authentication from '../helpers/authentication'; +import { join } from 'path'; +import { loadSchemaSync } from '@graphql-tools/load'; +import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'; +import { addResolversToSchema } from '@graphql-tools/schema'; +import resolvers from '../graphql/resolvers'; + +const schema = loadSchemaSync(join(__dirname, '../graphql/schema.graphql'), { + loaders: [new GraphQLFileLoader()], +}); + +const schemaWithResolvers = addResolversToSchema({ + schema, + resolvers, +}); const graphQLInstance = graphqlHTTP({ - schema: applyMiddleware(graphQLSchema, authentication), + schema: applyMiddleware(schemaWithResolvers, authentication), graphiql: true, customFormatErrorFn: (error) => { logger.error(error.path + ' : ' + error.message + '\n' + error.stack); diff --git a/packages/backend/src/types/express/request-with-current-user.d.ts b/packages/backend/src/types/express/context.ts similarity index 52% rename from packages/backend/src/types/express/request-with-current-user.d.ts rename to packages/backend/src/types/express/context.ts index cc869973..4c37b3ba 100644 --- a/packages/backend/src/types/express/request-with-current-user.d.ts +++ b/packages/backend/src/types/express/context.ts @@ -1,8 +1,8 @@ import { Request } from 'express'; import User from '../../models/user'; -interface RequestWithCurrentUser extends Request { +interface Context extends Request { currentUser: User; } -export default RequestWithCurrentUser; +export default Context; diff --git a/yarn.lock b/yarn.lock index 525c1ed8..2c52c00e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -157,6 +157,24 @@ tslib "^2.3.0" zen-observable-ts "^1.2.0" +"@apollo/client@~3.2.5 || ~3.3.0 || ~3.4.0": + version "3.4.17" + resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.4.17.tgz#4972e19a49809e16d17c5adc67f45623a6dac135" + integrity sha512-MDt2rwMX1GqodiVEKJqmDmAz8xr0qJmq5PdWeIt0yDaT4GOkKYWZiWkyfhfv3raTk8PyJvbsNG9q2CqmUrlGfg== + dependencies: + "@graphql-typed-document-node/core" "^3.0.0" + "@wry/context" "^0.6.0" + "@wry/equality" "^0.5.0" + "@wry/trie" "^0.3.0" + graphql-tag "^2.12.3" + hoist-non-react-statics "^3.3.2" + optimism "^0.16.1" + prop-types "^15.7.2" + symbol-observable "^4.0.0" + ts-invariant "^0.9.0" + tslib "^2.3.0" + zen-observable-ts "~1.1.0" + "@babel/code-frame@7.12.11": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" @@ -2117,6 +2135,36 @@ tslib "~2.3.0" value-or-promise "1.0.11" +"@graphql-tools/graphql-file-loader@^7.3.4": + version "7.3.4" + resolved "https://registry.yarnpkg.com/@graphql-tools/graphql-file-loader/-/graphql-file-loader-7.3.4.tgz#61e3e7e6223a21fbdd987f2abaa6f14104ab7b4a" + integrity sha512-Q0/YtDq0APR6syRclsQMNguWKRlchd8nFTOpLhfc7Xeiy21VhEEi4Ik+quRySfb7ubDfJGhiUq4MQW43FhWJvg== + dependencies: + "@graphql-tools/import" "^6.6.6" + "@graphql-tools/utils" "^8.6.2" + globby "^11.0.3" + tslib "~2.3.0" + unixify "^1.0.0" + +"@graphql-tools/import@^6.6.6": + version "6.6.6" + resolved "https://registry.yarnpkg.com/@graphql-tools/import/-/import-6.6.6.tgz#a4ff216e6b8a49c392bb8a4378d4e9caf2b303d7" + integrity sha512-a0aVajxqu1MsL8EwavA44Osw20lBOIhq8IM2ZIHFPP62cPAcOB26P+Sq57DHMsSyX5YQ0ab9XPM2o4e1dQhs0w== + dependencies: + "@graphql-tools/utils" "8.6.2" + resolve-from "5.0.0" + tslib "~2.3.0" + +"@graphql-tools/load@^7.5.2": + version "7.5.2" + resolved "https://registry.yarnpkg.com/@graphql-tools/load/-/load-7.5.2.tgz#0e46129f412bd038ac56996083458c1b8828526f" + integrity sha512-URPqVP77mYxdZxT895DzrWf2C23S3yC/oAmXD4D4YlxR5eVVH/fxu0aZR78WcEKF331fWSiFwWy9j7BZWvkj7g== + dependencies: + "@graphql-tools/schema" "8.3.2" + "@graphql-tools/utils" "^8.6.2" + p-limit "3.1.0" + tslib "~2.3.0" + "@graphql-tools/merge@^8.2.3": version "8.2.3" resolved "https://registry.yarnpkg.com/@graphql-tools/merge/-/merge-8.2.3.tgz#a2861fec230ee7be9dc42d72fed2ac075c31669f" @@ -2125,7 +2173,7 @@ "@graphql-tools/utils" "^8.6.2" tslib "~2.3.0" -"@graphql-tools/schema@^8.3.2": +"@graphql-tools/schema@8.3.2", "@graphql-tools/schema@^8.2.0", "@graphql-tools/schema@^8.3.2": version "8.3.2" resolved "https://registry.yarnpkg.com/@graphql-tools/schema/-/schema-8.3.2.tgz#5b949d7a2cc3936f73507d91cc609996f1266d11" integrity sha512-77feSmIuHdoxMXRbRyxE8rEziKesd/AcqKV6fmxe7Zt+PgIQITxNDew2XJJg7qFTMNM43W77Ia6njUSBxNOkwg== @@ -2135,7 +2183,7 @@ tslib "~2.3.0" value-or-promise "1.0.11" -"@graphql-tools/utils@^8.6.2": +"@graphql-tools/utils@8.6.2", "@graphql-tools/utils@^8.6.2": version "8.6.2" resolved "https://registry.yarnpkg.com/@graphql-tools/utils/-/utils-8.6.2.tgz#095408135f091aac68fe18a0a21b708e685500da" integrity sha512-x1DG0cJgpJtImUlNE780B/dfp8pxvVxOD6UeykFH5rHes26S4kGokbgU8F1IgrJ1vAPm/OVBHtd2kicTsPfwdA== @@ -4518,6 +4566,11 @@ resolved "https://registry.yarnpkg.com/@types/yup/-/yup-0.29.11.tgz#d654a112973f5e004bf8438122bd7e56a8e5cd7e" integrity sha512-9cwk3c87qQKZrT251EDoibiYRILjCmxBvvcb4meofCmx1vdnNcR9gyildy5vOHASpOKMsn42CugxUvcwK5eu1g== +"@types/zen-observable@0.8.3": + version "0.8.3" + resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.3.tgz#781d360c282436494b32fe7d9f7f8e64b3118aa3" + integrity sha512-fbF6oTd4sGGy0xjHPKAt+eS2CrxJ3+6gQ3FGcBoIJR2TLAyCkCyI8JqZNy+FeON0AhVgNJoUumVoZQjBFUqHkw== + "@typescript-eslint/eslint-plugin@^4.31.2": version "4.33.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.33.0.tgz#c24dc7c8069c7706bc40d99f6fa87edcb2005276" @@ -9543,6 +9596,16 @@ graphql-tag@^2.12.3: dependencies: tslib "^2.1.0" +graphql-tools@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/graphql-tools/-/graphql-tools-8.2.0.tgz#493edc2760469f39d8334c6f20aa75ae91a7ab86" + integrity sha512-9axT/0exEzVCk+vMPykOPannlrA4VQNo6nuWgh25IJ5arPf92OKxvjSHAbm7dQIFmcWxE0hVvyD2rWHjDqZCgQ== + dependencies: + "@graphql-tools/schema" "^8.2.0" + tslib "~2.3.0" + optionalDependencies: + "@apollo/client" "~3.2.5 || ~3.3.0 || ~3.4.0" + graphql-type-json@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/graphql-type-json/-/graphql-type-json-0.3.2.tgz#f53a851dbfe07bd1c8157d24150064baab41e115" @@ -12819,6 +12882,13 @@ normalize-package-data@^3.0.0, normalize-package-data@^3.0.2, normalize-package- semver "^7.3.4" validate-npm-package-license "^3.0.1" +normalize-path@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" + integrity sha1-GrKLVW4Zg2Oowab35vogE3/mrtk= + dependencies: + remove-trailing-separator "^1.0.1" + normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" @@ -13323,6 +13393,13 @@ p-finally@^1.0.0: resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= +p-limit@3.1.0, p-limit@^3.0.2: + version "3.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" + integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== + dependencies: + yocto-queue "^0.1.0" + p-limit@^1.1.0: version "1.3.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8" @@ -13337,13 +13414,6 @@ p-limit@^2.0.0, p-limit@^2.2.0: dependencies: p-try "^2.0.0" -p-limit@^3.0.2: - version "3.1.0" - resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b" - integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ== - dependencies: - yocto-queue "^0.1.0" - p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" @@ -15657,16 +15727,16 @@ resolve-cwd@^3.0.0: dependencies: resolve-from "^5.0.0" +resolve-from@5.0.0, resolve-from@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" + integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== + resolve-from@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== -resolve-from@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" - integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== - resolve-pathname@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd" @@ -17397,7 +17467,7 @@ ts-custom-error@^3.2.0: resolved "https://registry.yarnpkg.com/ts-custom-error/-/ts-custom-error-3.2.0.tgz#ff8f80a3812bab9dc448536312da52dce1b720fb" integrity sha512-cBvC2QjtvJ9JfWLvstVnI45Y46Y5dMxIaG1TDMGAD/R87hpvqFL+7LhvUDhnRCfOnx/xitollFWWvUKKKhbN0A== -ts-invariant@^0.9.4: +ts-invariant@^0.9.0, ts-invariant@^0.9.4: version "0.9.4" resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.9.4.tgz#42ac6c791aade267dd9dc65276549df5c5d71cac" integrity sha512-63jtX/ZSwnUNi/WhXjnK8kz4cHHpYS60AnmA6ixz17l7E12a5puCWFlNpkne5Rl0J8TBPVHpGjsj4fxs8ObVLQ== @@ -17802,6 +17872,13 @@ universalify@^2.0.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== +unixify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unixify/-/unixify-1.0.0.tgz#3a641c8c2ffbce4da683a5c70f03a462940c2090" + integrity sha1-OmQcjC/7zk2mg6XHDwOkYpQMIJA= + dependencies: + normalize-path "^2.1.1" + unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" @@ -18954,6 +19031,14 @@ zen-observable-ts@^1.2.0: dependencies: zen-observable "0.8.15" +zen-observable-ts@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-1.1.0.tgz#2d1aa9d79b87058e9b75698b92791c1838551f83" + integrity sha512-1h4zlLSqI2cRLPJUHJFL8bCWHhkpuXkF+dbGkRaWjgDIG26DmzyshUMrdV/rL3UnR+mhaX4fRq8LPouq0MYYIA== + dependencies: + "@types/zen-observable" "0.8.3" + zen-observable "0.8.15" + zen-observable@0.8.15: version "0.8.15" resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"