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,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;
|
||||
|
Reference in New Issue
Block a user