All files / services/utils/gql/types resolve.ts

92.59% Statements 25/27
94.44% Branches 17/18
75% Functions 3/4
92.31% Lines 24/26
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 459x 9x 9x 9x 9x   69x 69x 1x   68x 44x   24x 1x   23x 2x   21x 10x   11x 3x   8x   9x   1x 1x 2x             9x            
import { isType, GraphQLType } from 'graphql';
import { Thunk, AnyClass } from 'services/types';
import { objectTypeRegistry, compileObjectType } from 'domains';
import { enumsRegistry, unionRegistry } from 'domains';
import { parseNativeTypeToGraphQL, isParsableScalar } from './parseNative';
 
export function resolveType(input: any, allowThunk = true): GraphQLType {
  if (isType(input)) {
    return input;
  }
 
  if (isParsableScalar(input)) {
    return parseNativeTypeToGraphQL(input);
  }
 
  if (enumsRegistry.has(input)) {
    return enumsRegistry.get(input);
  }
 
  if (unionRegistry.has(input)) {
    return unionRegistry.get(input)();
  }
 
  if (objectTypeRegistry.has(input)) {
    return compileObjectType(input);
  }
 
  if (!allowThunk || typeof input !== 'function') {
    return;
  }E
 
  return resolveType(input(), false);
}
 
export function resolveTypes(types: Thunk<any[]>): GraphQLType[] {
  if (Array.isArray(types)) {
    return types.map(type => {
      return resolveType(type);
    });
  }
  return types().map(type => {
    return resolveType(type);
  });
}