Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fastifyGraphQl.defineLoaders = function (loaders) {
// set up the loaders factory
if (!factory) {
factory = new Factory()
app.decorateReply(kLoaders)
app.addHook('onRequest', async function (req, reply) {
reply[kLoaders] = factory.create({ req, reply, app })
})
}
function defineLoader (name) {
// async needed because of throw
return async function (obj, params, { reply }) {
if (!reply) {
throw new Error('loaders only work via reply.graphql()')
}
return reply[kLoaders][name]({ obj, params })
}
}