# All files / decorators/gapi-object-type gapi-object-type.ts

86.67% Statements 13/15
66.67% Branches 8/12
80% Functions 4/5
92.31% Lines 12/13

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
    6x

    6x
    6x
    6x
    6x
    6x
    10x
    6x

    6x
    1x

    5x
    8x

     import { Container } from '../../utils/container';
    import { GraphQLObjectType, GraphQLInputObjectType } from 'graphql';

    interface ResolveMetadata<T> {
        resolve?: () => T;
        key?: string;
    }

    export function GapiObjectType<T>(options?: { input: boolean, raw: boolean }): Function {
        return function (target: any, propertyName: string, index?: number) {
            const userTypes = new target();
            const type = Object.create({ fields: {}, name: target.name });
            const metadata: { [key: string]: ResolveMetadata<T> } = {};
            Object.keys(userTypes).forEach(field => type.fields[field] = { type: userTypes[field] });
            Iif (target.prototype._metadata && target.prototype._metadata.length) {
                target.prototype._metadata.forEach(meta => type.fields[meta.key].resolve = meta.resolve.bind(target.prototype));
            }
            if (options && options.raw) {
                return target;
            } else {
                return function () {
                    return options && options.input ? new GraphQLInputObjectType(type) : new GraphQLObjectType(type);
                };
            }

        };
    }