Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 19x 19x 19x 19x 19x 19x 19x 89x 89x 85x 84x 80x 80x 80x 19x 62x 62x 62x 73x 1x 72x 72x 52x 58x 58x 58x 62x 48x 19x | import { GraphQLFieldConfig, GraphQLFieldConfigMap } from 'graphql'; import { getClassWithAllParentClasses } from '~/services/utils/inheritance'; import { FieldError, fieldsRegistry } from '../index'; import { compileFieldResolver } from './resolver'; import { compileFieldArgs } from '~/domains/arg'; import { enhanceType, isRootFieldOnNonRootBase, resolveRegisteredOrInferedType, validateResolvedType, } from './services'; I import { validateNotInferableField } from './fieldType'; export function compileFieldConfig( taIrget: Function, fieldName: string, ): GraphQLFieldConfig<any, any, any> { const { type, description, isNullable } = fieldsRegistry.get( target, fieldName, ); const args = compileFieldArgs(target, fieldName); const resolvedType = resolveRegisteredOrInferedType(target, fieldName, type); // if was not able to resolve type, try to show some helpful information about it if (!resolvedType && !validateNotInferableField(target, fieldName)) { return; } // show error about being not able to resolve field type if (!validateResolvedType(target, fieldName, resolvedType)) { validateNotInferableField(target, fieldName); return; } const finalType = enhanceType(resolvedType, isNullable); return { description, type: finalType, resolve: compileFieldResolver(target, fieldName), args, }; } function getAllFields(target: Function) { const fields = fieldsRegistry.getAll(target); const finalFieldsMap: GraphQLFieldConfigMap<any, any> = {}; Object.keys(fields).forEach(fieldName => { if (isRootFieldOnNonRootBase(target, fieldName)) { throw new FieldError( target, fieldName, `Given field is root field (@Query or @Mutation) not registered inside @Schema type. `, ); } const config = fieldsRegistry.get(target, fieldName); finalFieldsMap[config.name] = compileFieldConfig(target, fieldName); }); return finalFieldsMap; } export function compileAllFields(target: Function) { const targetWithParents = getClassWithAllParentClasses(target); const finalFieldsMap: GraphQLFieldConfigMap<any, any> = {}; targetWithParents.forEach(targetLevel => { Object.assign(finalFieldsMap, getAllFields(targetLevel)); }); return finalFieldsMap; } |