Skip to content

Commit

Permalink
Removed unused methods in DynamicResolverBase
Browse files Browse the repository at this point in the history
  • Loading branch information
incetarik committed Aug 21, 2022
1 parent e254691 commit e421841
Showing 1 changed file with 2 additions and 74 deletions.
76 changes: 2 additions & 74 deletions src/dynamic-resolver/dynamic-resolver-base.ts
Original file line number Diff line number Diff line change
@@ -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<string>) {
const select = extractGraphQLSelections({
node: info.fieldNodes[ 0 ],
selectionMap,
})

return select
}

protected getSelectionPath(info: GraphQLResolveInfo, selectionMap?: Dictionary<string>) {
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<string>) {
const {
relation,
Expand Down

0 comments on commit e421841

Please sign in to comment.