chore: Add available app enum type to validate app keys
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
23621d1b06
commit
81d04e417d
@@ -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)
|
||||||
|
@@ -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;
|
Reference in New Issue
Block a user