@nestjs/graphql
Version:
Nest - modern, fast, powerful node.js web framework (@graphql)
18 lines (17 loc) • 630 B
JavaScript
import { GraphQLScalarType } from 'graphql';
function bindInstanceContext(instance, funcKey) {
return instance[funcKey]
? instance[funcKey].bind(instance)
: undefined;
}
export function createScalarType(name, instance) {
return new GraphQLScalarType({
name,
description: instance.description,
specifiedByURL: instance.specifiedByURL,
extensions: instance.extensions,
parseValue: bindInstanceContext(instance, 'parseValue'),
serialize: bindInstanceContext(instance, 'serialize'),
parseLiteral: bindInstanceContext(instance, 'parseLiteral'),
});
}