INNER CODE UNIT · TypeScript
prepareContext
Diizzayy/nuxt-graphql-client · src/context.ts:20
export async function prepareContext(ctx: GqlContext, prefix: string) {
if (ctx.clientDocs) { await prepareOperations(ctx) }
if (ctx.template) { prepareTemplate(ctx) }
ctx.fns = Object.values(ctx.template || {}).reduce((acc, template) => {
const fns = template.match(ctx?.codegen ? /\w+\s*(?=\(variables)/g : /\w+(?=:\s\(variables)/g)?.sort() || []
return [...acc, ...fns]
}, [] as string[])
const fnName = (fn: string) => prefix + upperFirst(fn)
const fnExp = (fn: string, typed = false) => {
const name = fnName(fn)
if (!typed) { return `export const ${name} = (...params) => useGql()('${fn}', ...params)` }