UNPKG

@graphql-codegen/typescript-react-query

Version:

GraphQL Code Generator plugin for generating a ready-to-use React-Query Hooks based on GraphQL operations

47 lines (46 loc) 1.88 kB
import { GraphQLSchema, OperationDefinitionNode } from 'graphql'; import { Types } from '@graphql-codegen/plugin-helpers'; import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common'; import { ReactQueryRawPluginConfig } from './config.cjs'; import { FetcherRenderer } from './fetcher.cjs'; export interface ReactQueryPluginConfig extends ClientSideBasePluginConfig { errorType: string; exposeDocument: boolean; exposeQueryKeys: boolean; exposeQueryRootKeys: boolean; exposeMutationKeys: boolean; exposeFetcher: boolean; addInfiniteQuery: boolean; legacyMode: boolean; reactQueryImportFrom?: string; } export interface ReactQueryMethodMap { infiniteQuery: { hook: string; options: string; }; query: { hook: string; options: string; }; mutation: { hook: string; options: string; }; } export declare class ReactQueryVisitor extends ClientSideBaseVisitor<ReactQueryRawPluginConfig, ReactQueryPluginConfig> { protected rawConfig: ReactQueryRawPluginConfig; private _externalImportPrefix; fetcher: FetcherRenderer; reactQueryHookIdentifiersInUse: Set<string>; reactQueryOptionsIdentifiersInUse: Set<string>; queryMethodMap: ReactQueryMethodMap; constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: ReactQueryRawPluginConfig, documents: Types.DocumentFile[]); get imports(): Set<string>; private createFetcher; get hasOperations(): boolean; getImports(): string[]; getFetcherImplementation(): string; private _getHookSuffix; protected buildOperation(node: OperationDefinitionNode, documentVariableName: string, operationType: string, operationResultType: string, operationVariablesTypes: string, hasRequiredVariables: boolean): string; }