All files / domains/field/compiler fieldType.ts

92.86% Statements 13/14
75% Branches 3/4
100% Functions 2/2
92.86% Lines 13/14
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 319x 9x 9x 9x   7x 7x 1x   6x   9x   28x 28x     28x   9x                      
import { inferTypeByTarget } from 'services/utils';
import { FieldError, fieldsRegistry } from '../index';
 
import { resolveType } from 'services/utils';
 
export function resolveTypeOrThrow(type: any, target: Function, fieldName: string) {
  const resolvedType = resolveType(type);
 
  if (!resolvedType) {
    throw new FieldError(
      target,
      fieldName,
      `Forced type is incorrect. Make sure to use either native graphql type or class that is registered with @Type decorator`,
    );
  }I

  return resolvedType;
}
 
export function inferTypeOrThrow(target: Function, fieldName: string) {
  const inferedType = inferTypeByTarget(target.prototype, fieldName);
  if (!inferedType) {
    throw new FieldError(
      target,
      fieldName,
      `Could not infer return type and no type is forced. In case of circular dependencies make sure to force types of instead of infering them.`,
    );
  }
  return resolveType(inferedType);
}