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

90.91% Statements 20/22
71.43% Branches 10/14
100% Functions 3/3
90.91% Lines 20/22

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 4017x 17x 17x   116x   17x   73x 65x   8x 5x   3x 3x     17x     54x     54x 54x 30x   24x 24x     24x   17x          
import { GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLScalarType } from 'graphql';
import 'reflect-metadata';
export type ParsableScalar = String | Number | Boolean;
 
export function isParsableScalar(input: any): input is ParsableScalar {
  return [String, Number, Boolean].includes(input);
}
 
export function parseNativeTypeToGraphQL(input: any): GraphQLScalarType {
  if (input === String) {
    return GraphQLString;
  }
  if (input === Number) {
    return GraphQLFloat;
  }E
  if (input === Boolean) {
    return GraphQLBoolean;
  }
}
 
// type MetadataType = 'design:returntype' | 'design:type' | 'design:paramtypes';
I
export function inferTypeByTarget(target: Function, key?: string) {
  if (!key) {
    return Reflect.getMetadata('design:type', target);
  }
 
  const returnType = Reflect.getMetadata('design:returntype', target, key);
  if (returnType) {
    Ireturn returnType;
  }
 
  const targetField = (target as any)[key];
 
  if (targetField && typeof targetField === 'function') {
    return Reflect.getMetadata('design:returntype', target, key);
  }
  return Reflect.getMetadata('design:type', target, key);
}