0.0.1 • Published 6 years ago

graphql-json-resolvers v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

graphql-json-resolvers Test Coverage Maintainability

Configure resolvers through JSON configuration rather than code

Configuring Resolvers

Resolver options are written in Velocity (via the velocityjs package). Resolver arguments and the process.env object are available as variables in the options.

$obj
$args
$ctx
$info
$env = process.env

See examples for usage examples.

Usage

import { compile } from 'graphql-json-resolvers'
import { addResolveFunctionsToSchema } from 'graphql-tools'

...

addResolveFunctionsToSchema(schema, compile(path.resolve(__dirname, './resolvers')))

Standard resolvers

Out of the box, graphql-json-resolvers includes several useful resolvers.

camelizeKeys

Convert the previously returned object to camelcase keys using the humps package.

Usage
{ "use": "camelizeKeys" }

http

Perform an http request using the axios package.

Options
url - *required*
method
responseType
url
headers
data
params
timeout
baseURL
withCredentials
proxy
maxRedirects
maxContentLength
xsrfCookieName
xsrfHeaderName
Usage
{
  "use": "http",
  "options": {
    "url": "$env.BACKEND_URL/v1/acceptance_documents/$args.type",
    "timeout": 5000
  }
}

ramda

Perform one of the functions in the ramda library.

Options
fn - *required*
args
Usage
{
  "use": "ramda",
  "options": {
    "fn": "path",
    "args": [
      ["acceptance_document"]
    ]
  }
}

Adding custom resolvers

Basic Example:

import { addResolver } from 'graphql-json-resolvers'

const fooResolver = (options) => (obj, args, context, info) => 'foo'

addResolver('foo', fooResolver)

Demo

Take a look at the demo server to see just how easy setting up GraphQL using graphql-json-resolvers can be.

yarn demo