All files / domains/schema rootFields.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 3/3
100% Lines 11/11
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 269x 9x 9x     3x 3x 3x 2x 2x 2x   3x     9x                    
import { Field, fieldsRegistry, compileFieldConfig } from 'domains/field';
import { SchemaError, SchemaFieldError } from './error';
 
import { schemaRegistry, queryFieldsRegistry } from './registry';
import { GraphQLOutputType } from 'graphql';
import { isObjectType } from 'services/utils';
 
interface FieldOptions {
  description?: string;
  type?: any;
  name?: string;
}
 
// special fields
export function Query(options?: FieldOptions): PropertyDecorator {
  return (targetInstance: Object, fieldName: string) => {
    Field(options)(targetInstance, fieldName);
    const fieldCompiler = () => {
      const compiledField = compileFieldConfig(targetInstance.constructor, fieldName);
      compiledField.type;
      return compiledField;
    };
    queryFieldsRegistry.set(targetInstance.constructor, fieldName, fieldCompiler);
  };
}