INNER CODE UNIT · TypeScript

prepareTemplate

Diizzayy/nuxt-graphql-client · src/context.ts:102

function prepareTemplate(ctx: GqlContext) {
  if (!ctx.codegen) { return }

  ctx.clientTypes ||= {}

  ctx.clientTypes = Object.entries(ctx.template || {}).reduce((acc, [key, template]) => {
    const results = template.match(/^export\stype\s\w+(?=\s=\s)/gm)
      ?.filter(e => !['Scalars', 'SdkFunctionWrapper', 'Sdk'].some(f => e.includes(f)))
      .map(e => e.replace('export type ', ''))

    if (!results) { return acc }

    return { ...acc, [key]: results }
  }, {} as Record<string, string[]>)
}

export const mockTemplate = (operations: Record<string, string>) => {
  const GqlFunctions: string[] = []

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…