API¶
GraphQLFactory
instance¶
GraphQLFactory requires graphql to be passed as its only parameter to create a factory instance:
const factory = GraphQLFactory(graphql)
Hint
When using import
to load graphql
all exports should be imported with import * as graphql from 'graphql'
factory
prototype¶
The factory prototype is used to create a library
make()
¶
Signature: make(Object definition [, Object options])
Creates a new library
factory.make(definition, {
plugin: [
new TypesPlugin(),
new SubscriptionPlugin()
],
beforeMiddleware: [
function (params, next) {
const { source, args, context, info } = params
args.before = true
return next()
}
],
afterMiddleware: [
function (params, result, next) {
result.after = true
return next(result)
}
]
})
Options
compile
When false skips the compile processplugin
Array of pluginsbeforeMiddleware
Array of before middlewareafterMiddleWare
Array of after middlewarebeforeTimeout
Timeout for all before middleware to completeafterTimeout
Timeout for all after middleware to complete
Returns GraphQLFactoryLibrary
GraphQLFactoryLibrary
instance¶
The GraphQLFactoryLibrary prototype is used to make graphql requests and access the definition. Each schema in the definition will have its own method in the library
<schemaName>()
¶
Signature: <schemaName>(String request [, Object root, Object context, Object variables, String operation])
Makes a new graphql request
lib.Users(`
query Query {
listUsers {
id
name
email
}
}
`)
Options:
request
graphql requestStringroot
graphql rootValuecontext
graphql contextvariables
graphql variableValuesoperation
graphql operationName