yeah graphql have scalars, but? but?
! since 2.0.0 typescript support available, i rewriten this library with typescript.
straight forward:
Make sure you install yup first:
yarn add yup
Then install this lib:
yarn add graphql-yup-resolver
/* your-resolver.js */
const createYupResolver = require('graphql-yup-resolver');
const fn = createYupResolver({
// graphql args
args: {
name: yup.string().required().min(3),
},
// actual resolver, protected by yup
resolver: (_, { name }) => `hello ${name}!`,
});
/* src/index.ts */
import Pino from 'pino';
import makeResolver from "graphql-yup-resolver";
import { isConstructorDeclaration } from "typescript";
import * as yup from 'yup';
const logger = Pino({
transport: {
target: "pino-pretty",
},
});
const hello = makeResolver({
args: { name: yup.string() },
resolver: (_: any, { name }: { name: string }) => `hello ${name}!`,
});
(async () => {
const result = await hello({}, { name: "ryan" });
logger.info(result); // just dump to console the result
})();
Node-Target-Mapping
Current build focused to node 10