From e42184142845791f4a6b5532c9d96c15e1c02e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tar=C4=B1k=20=C4=B0nce?= Date: Sun, 21 Aug 2022 13:18:38 +0300 Subject: [PATCH] Removed unused methods in `DynamicResolverBase` --- src/dynamic-resolver/dynamic-resolver-base.ts | 76 +------------------ 1 file changed, 2 insertions(+), 74 deletions(-) diff --git a/src/dynamic-resolver/dynamic-resolver-base.ts b/src/dynamic-resolver/dynamic-resolver-base.ts index ab1c41a..a737966 100644 --- a/src/dynamic-resolver/dynamic-resolver-base.ts +++ b/src/dynamic-resolver/dynamic-resolver-base.ts @@ -1,82 +1,10 @@ -import { GraphQLResolveInfo } from 'graphql' - -import { getNavigationMaps, INavigationMap } from '../dynamic-navigations' -import { - extractGraphQLSelectionPath, - extractGraphQLSelections, - toCamelCase, - updatePathInfoFromSchema, -} from '../helpers' - +import type { GraphQLResolveInfo } from 'graphql' +import type { INavigationMap } from '../dynamic-navigations' import type { Dictionary } from '../types' export abstract class DynamicResolverBase { constructor(protected readonly prisma: any) {} - protected getSelectionObject(info: GraphQLResolveInfo, selectionMap?: Dictionary) { - const select = extractGraphQLSelections({ - node: info.fieldNodes[ 0 ], - selectionMap, - }) - - return select - } - - protected getSelectionPath(info: GraphQLResolveInfo, selectionMap?: Dictionary) { - const selectionPath = extractGraphQLSelectionPath({ - path: info.path, - }) - - const pathInfoList = selectionPath - pathInfoList.forEach(pathInfo => { - if (pathInfo.table) return - - const tableName = toCamelCase(pathInfo.tableName) - const maps = getNavigationMaps() - .filter(it => it.sourceTableName === tableName) - - pathInfo.table = maps[ 0 ]?.source - pathInfo.navigationMaps = maps - - updatePathInfoFromSchema(pathInfo, info.schema) - }) - - const query = pathInfoList[ 0 ] - - if (pathInfoList.length < 3) { - throw new Error(`The navigation source could not be extracted in (${query.propertyName})`) - } - - const firstLink = pathInfoList[ 1 ] - - if (!firstLink.table) { - throw new Error(`The navigation target could not be extracted in (${query.propertyName}): '${firstLink.propertyName}' → ?`) - } - - const secondLink = pathInfoList[ 2 ] - - if (!secondLink.table) { - throw new Error(`The navigation target could not be extracted in (${query.propertyName}): ${firstLink.propertyName} → ${secondLink.propertyName}' → ?`) - } - - const sourceTableName - = selectionMap?.[ firstLink.propertyName ] - ?? toCamelCase(firstLink.table.name) - - const source = this.prisma[ sourceTableName ] - if (!source) { - throw new Error(`Unrecognized Prisma model: "${sourceTableName}". Failed to build resolver for navigation: '${sourceTableName} → ${secondLink.propertyName}'`) - } - - return { - to: secondLink, - root: query, - from: firstLink, - source, - selectionPath, - } - } - protected resolve(parent: any, _primaryKeyName: string, _info: GraphQLResolveInfo, navigationMap: INavigationMap, _selectionMap?: Dictionary) { const { relation,