chore: Add available app enum type to validate app keys

This commit is contained in:
Faruk AYDIN
2021-11-24 16:48:42 +01:00
committed by Ömer Faruk Aydın
parent 23621d1b06
commit 81d04e417d
2 changed files with 20 additions and 2 deletions

View File

@@ -1,7 +1,8 @@
import { GraphQLString, GraphQLNonNull } from 'graphql'; import { GraphQLString, GraphQLNonNull, GraphQLEnumType } from 'graphql';
import Connection from '../../models/connection'; import Connection from '../../models/connection';
import App from '../../models/app'; import App from '../../models/app';
import connectionType from '../types/connection'; import connectionType from '../types/connection';
import availableAppsEnumType from '../types/available-apps-enum-type';
import RequestWithCurrentUser from '../../types/express/request-with-current-user'; import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import { GraphQLJSONObject } from 'graphql-type-json'; import { GraphQLJSONObject } from 'graphql-type-json';
@@ -27,7 +28,7 @@ const createConnectionResolver = async (params: Params, req: RequestWithCurrentU
const createConnection = { const createConnection = {
type: connectionType, type: connectionType,
args: { args: {
key: { type: GraphQLNonNull(GraphQLString) }, key: { type: availableAppsEnumType },
data: { type: GraphQLNonNull(GraphQLJSONObject) } data: { type: GraphQLNonNull(GraphQLJSONObject) }
}, },
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createConnectionResolver(params, req) resolve: (_: any, params: Params, req: RequestWithCurrentUser) => createConnectionResolver(params, req)

View File

@@ -0,0 +1,17 @@
import { GraphQLEnumType } from 'graphql';
import App from '../../models/app';
import appInfoType from '../../types/app-info'
const apps = App.findAll();
const availableAppEnumValues: any = {}
apps.forEach((app: appInfoType) => {
availableAppEnumValues[app.key] = { value: app.key }
})
const availableAppsEnumType = new GraphQLEnumType({
name: 'AvailableAppsEnumType',
values: availableAppEnumValues
})
export default availableAppsEnumType;