import { B as BaseAnalyzer } from '../dataflow-analyzer-Woim3nqS.js'; export { D as DataFlowAnalyzer, G as GraphQLAnalyzer, P as PagesAnalyzer } from '../dataflow-analyzer-Woim3nqS.js'; import { Module, CallExpression } from '@swc/core'; import { DataFetchingInfo, RepositoryConfig, AnalysisResult } from '../types.js'; /** * Unified GraphQL extraction utilities * * This module provides a single source of truth for all GraphQL operation extraction. * All analyzers should use these utilities instead of implementing their own logic. */ /** * All supported Apollo/GraphQL query hooks */ declare const GRAPHQL_QUERY_HOOKS: readonly ["useQuery", "useLazyQuery", "useSuspenseQuery", "useBackgroundQuery", "useReadQuery"]; /** * All supported Apollo/GraphQL mutation hooks */ declare const GRAPHQL_MUTATION_HOOKS: readonly ["useMutation"]; /** * All supported Apollo/GraphQL subscription and other hooks */ declare const GRAPHQL_OTHER_HOOKS: readonly ["useSubscription", "useFragment", "useApolloClient"]; /** * All GraphQL hooks combined */ declare const ALL_GRAPHQL_HOOKS: readonly ["useQuery", "useLazyQuery", "useSuspenseQuery", "useBackgroundQuery", "useReadQuery", "useMutation", "useSubscription", "useFragment", "useApolloClient"]; /** * Hook type mapping for data fetching info */ declare const HOOK_TYPE_MAP: Record; /** * Keywords that indicate GraphQL usage in a file */ declare const GRAPHQL_INDICATORS: readonly ["Document", "useQuery", "useMutation", "useLazyQuery", "useSuspenseQuery", "useBackgroundQuery", "useSubscription", "Query", "Mutation", "gql", "graphql", "GET_", "FETCH_", "SEARCH_", "CREATE_", "UPDATE_", "DELETE_", "SUBSCRIBE_", "@apollo", "ApolloClient", "@urql", "urql", "react-relay", "Relay"]; /** * Context extracted from a file for GraphQL operation resolution */ interface GraphQLFileContext { /** Document imports: import { GetUserDocument } from '...' */ documentImports: Map; /** Variable -> operation name mapping from gql() calls */ variableOperations: Map; /** Static property mappings: Component.Query = gql`...` */ staticPropertyOperations: Map; /** Codegen mapping: Document name -> operation name */ codegenMap: Map; } /** * Result of extracting GraphQL operations from a hook call */ interface ExtractedGraphQLOperation { operationName: string; hookName: string; type: DataFetchingInfo['type']; variables?: Record; } /** * Check if a hook name is a GraphQL query hook */ declare function isQueryHook(hookName: string, extraHookPatterns?: string[]): boolean; /** * Check if a hook name is a GraphQL mutation hook */ declare function isMutationHook(hookName: string, extraHookPatterns?: string[]): boolean; /** * Check if a hook name is a GraphQL subscription hook */ declare function isSubscriptionHook(hookName: string, extraHookPatterns?: string[]): boolean; /** * Check if a hook name is any GraphQL hook */ declare function isGraphQLHook(hookName: string, extraHookPatterns?: string[]): boolean; /** * Get the data fetching type for a hook */ declare function getHookType(hookName: string, extraHookPatterns?: string[]): DataFetchingInfo['type']; /** * Check if content has any GraphQL indicators */ declare function hasGraphQLIndicators(content: string): boolean; /** * Clean operation name by removing common suffixes */ declare function cleanOperationName(name: string): string; /** * Safely parse TypeScript/TSX content to AST */ declare function parseToAst(content: string): Module | null; /** * Get callee name from a call expression */ declare function getCalleeName(callee: any): string | null; /** * Traverse AST and call callback for each node */ declare function traverseAst(node: any, callback: (node: any) => void): void; /** * Extract all GraphQL context from a file in a single AST pass * This is the main entry point for file-level analysis */ declare function extractGraphQLContext(ast: Module, content: string, codegenMap?: Map): GraphQLFileContext; /** * Extract operation name from gql() function call */ declare function extractOperationNameFromGqlCall(call: any, content: string): string | null; /** * Extract operation name from template literal */ declare function extractOperationNameFromTemplate(template: any, _content: string): string | null; /** * Check if a hook call has GraphQL-related arguments * This verifies the hook is actually used for GraphQL, not just has a similar name * e.g., useQueryParams() is NOT a GraphQL hook, but useQuery(GetUserDocument) IS */ declare function hasGraphQLArgument(call: CallExpression, content: string, context: GraphQLFileContext): boolean; /** * Resolve operation name from a hook call using file context * This is the main API for resolving operation names */ declare function resolveOperationName(call: CallExpression, content: string, context: GraphQLFileContext): string | null; /** * Extract all GraphQL operations from a file * Returns a list of operations with their hook names and types */ declare function extractGraphQLOperationsFromFile(content: string, codegenMap?: Map): ExtractedGraphQLOperation[]; /** * Get displayable hook info string (for backward compatibility) */ declare function getHookInfoString(op: ExtractedGraphQLOperation): string; /** * Analyzer for REST API calls (fetch, axios, useSWR, etc.) * Uses @swc/core for fast parsing */ declare class RestApiAnalyzer extends BaseAnalyzer { private apiCallCounter; constructor(config: RepositoryConfig); getName(): string; analyze(): Promise>; /** * Analyze a parsed module for API calls */ private analyzeModule; /** * Traverse AST nodes recursively */ private traverseNode; /** * Analyze a call expression for API calls */ private analyzeCallExpression; /** * Get callee name from expression */ private getCalleeName; /** * Extract API call from fetch() */ private extractFetchCall; /** * Extract API call from axios.method() */ private extractAxiosMethodCall; /** * Extract API call from axios() direct call */ private extractAxiosDirectCall; /** * Extract API call from useSWR() */ private extractSwrCall; /** * Extract URL from an expression */ private extractUrlFromExpression; /** * Get line number from byte offset */ private getLineNumber; /** * Static file extensions to exclude from API detection */ private static readonly STATIC_FILE_EXTENSIONS; /** * Non-API URL schemes to exclude */ private static readonly NON_API_SCHEMES; /** * Check if URL looks like an API endpoint (generic approach) * Uses exclusion-based logic: if it's not a static file, it's likely an API */ private isApiUrl; /** * Known external service patterns for categorization */ private static readonly SERVICE_PATTERNS; /** * Categorize API by URL pattern (generic approach) * Automatically extracts service name from domain if not in known patterns */ private categorizeApi; /** * Normalize HTTP method */ private normalizeMethod; } export { ALL_GRAPHQL_HOOKS, BaseAnalyzer, type ExtractedGraphQLOperation, GRAPHQL_INDICATORS, GRAPHQL_MUTATION_HOOKS, GRAPHQL_OTHER_HOOKS, GRAPHQL_QUERY_HOOKS, type GraphQLFileContext, HOOK_TYPE_MAP, RestApiAnalyzer, cleanOperationName, extractGraphQLContext, extractGraphQLOperationsFromFile, extractOperationNameFromGqlCall, extractOperationNameFromTemplate, getCalleeName, getHookInfoString, getHookType, hasGraphQLArgument, hasGraphQLIndicators, isGraphQLHook, isMutationHook, isQueryHook, isSubscriptionHook, parseToAst, resolveOperationName, traverseAst };