Skip to content

ryanhs/graphql-yup-resolver

Repository files navigation

graphql-yup-resolver

npm node-current CircleCI Coverage Status

yeah graphql have scalars, but? but?

! since 2.0.0 typescript support available, i rewriten this library with typescript.

Installation

straight forward:

Make sure you install yup first:

yarn add yup

Then install this lib:

yarn add graphql-yup-resolver

Usage Example

/* 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}!`,

});

Usage Example (using typescript)

/* 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
})();

Build Targets

Node-Target-Mapping
Current build focused to node 10

LICENSE