refactor: Use graphql schema directly with graphql-tools library
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
96cca96bff
commit
9926e5589e
@@ -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;
|
@@ -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;
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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<any> => {
|
||||
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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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<any[]> => {
|
||||
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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
9
packages/backend/src/graphql/resolvers.ts
Normal file
9
packages/backend/src/graphql/resolvers.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import mutationResolvers from './mutation-resolvers';
|
||||
import queryResolvers from './query-resolvers';
|
||||
|
||||
const resolvers = {
|
||||
Query: queryResolvers,
|
||||
Mutation: mutationResolvers,
|
||||
};
|
||||
|
||||
export default resolvers;
|
272
packages/backend/src/graphql/schema.graphql
Normal file
272
packages/backend/src/graphql/schema.graphql
Normal file
@@ -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
|
||||
}
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -1,10 +0,0 @@
|
||||
import { GraphQLObjectType, GraphQLString } from 'graphql';
|
||||
|
||||
const authLinkType = new GraphQLObjectType({
|
||||
name: 'AuthLink',
|
||||
fields: {
|
||||
url: { type: GraphQLString }
|
||||
}
|
||||
})
|
||||
|
||||
export default authLinkType;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -1,10 +0,0 @@
|
||||
import { GraphQLString, GraphQLObjectType } from 'graphql';
|
||||
|
||||
const connectionDataType = new GraphQLObjectType({
|
||||
name: 'ConnectionData',
|
||||
fields: {
|
||||
screenName: { type: GraphQLString },
|
||||
}
|
||||
})
|
||||
|
||||
export default connectionDataType;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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);
|
||||
|
@@ -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;
|
Reference in New Issue
Block a user