INNER CODE UNIT · TypeScript

mockTemplate

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

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

  for (const [k, v] of Object.entries(operations)) {
    GqlFunctions.push(`    ${k}: (variables = undefined, requestHeaders = undefined) => withWrapper((wrappedRequestHeaders) => client.request(\`${v}\`, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${k}', 'query')`)
  }

  return [
    'export function getSdk(client, withWrapper = (action, _operationName, _operationType) => action()) {',
    '  return {',
    GqlFunctions.join(',\n'),
    '  }',
    '}'
  ].join('\n')
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…