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 | 7x 7x 7x 7x 7x 7x 11x 7x 7x 1x 6x 9x | 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);
};
}
};
}
|