0.0.1 • Published 8 years ago
graphql-json-resolvers v0.0.1
graphql-json-resolvers

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.envSee 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
humpspackage.
Usage
{ "use": "camelizeKeys" }http
Perform an http request using the
axiospackage.
Options
url - *required*
method
responseType
url
headers
data
params
timeout
baseURL
withCredentials
proxy
maxRedirects
maxContentLength
xsrfCookieName
xsrfHeaderNameUsage
{
"use": "http",
"options": {
"url": "$env.BACKEND_URL/v1/acceptance_documents/$args.type",
"timeout": 5000
}
}ramda
Perform one of the functions in the
ramdalibrary.
Options
fn - *required*
argsUsage
{
"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 demo0.0.1
8 years ago