chore: Use available apps enum type in queries and mutations

This commit is contained in:
Faruk AYDIN
2021-11-27 13:39:51 +01:00
committed by Ömer Faruk Aydın
parent 63d478f9a9
commit 9ea5242d94
3 changed files with 8 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
import { GraphQLString, GraphQLNonNull, GraphQLEnumType } from 'graphql'; import { GraphQLNonNull } 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';
@@ -28,7 +28,7 @@ const createConnectionResolver = async (params: Params, req: RequestWithCurrentU
const createConnection = { const createConnection = {
type: connectionType, type: connectionType,
args: { args: {
key: { type: availableAppsEnumType }, key: { type: GraphQLNonNull(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

@@ -1,8 +1,9 @@
import { GraphQLList, GraphQLString, GraphQLNonNull } from 'graphql'; import { GraphQLList, GraphQLNonNull } from 'graphql';
import Connection from '../../models/connection'; import Connection from '../../models/connection';
import App from '../../models/app'; import App from '../../models/app';
import RequestWithCurrentUser from '../../types/express/request-with-current-user'; import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import connectionType from '../types/connection'; import connectionType from '../types/connection';
import availableAppsEnumType from '../types/available-apps-enum-type';
type Params = { type Params = {
key: string key: string
@@ -22,7 +23,7 @@ const getAppConnectionsResolver = async (params: Params, req: RequestWithCurrent
const getAppConnections = { const getAppConnections = {
type: GraphQLList(connectionType), type: GraphQLList(connectionType),
args: { args: {
key: { type: GraphQLNonNull(GraphQLString) } key: { type: GraphQLNonNull(availableAppsEnumType) },
}, },
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppConnectionsResolver(params, req) resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppConnectionsResolver(params, req)
} }

View File

@@ -1,19 +1,15 @@
import { GraphQLString, GraphQLNonNull } from 'graphql'; import { GraphQLNonNull } from 'graphql';
import App from '../../models/app'; import App from '../../models/app';
import appType from '../types/app'; import appType from '../types/app';
import RequestWithCurrentUser from '../../types/express/request-with-current-user'; import RequestWithCurrentUser from '../../types/express/request-with-current-user';
import Connection from '../../models/connection'; import Connection from '../../models/connection';
import connectionType from '../types/connection'; import availableAppsEnumType from '../types/available-apps-enum-type';
type Params = { type Params = {
key: string key: string
} }
const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => { const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => {
if(!params.key) {
throw new Error('No key provided.')
}
const app = App.findOneByKey(params.key); const app = App.findOneByKey(params.key);
if (req.currentUser?.id) { if (req.currentUser?.id) {
@@ -32,7 +28,7 @@ const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => {
const getApp = { const getApp = {
type: appType, type: appType,
args: { args: {
key: { type: GraphQLNonNull(GraphQLString) }, key: { type: GraphQLNonNull(availableAppsEnumType) },
}, },
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppResolver(params, req) resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppResolver(params, req)
} }