/** * Smart GraphQL Tool - 83% Token Reduction * * GraphQL query optimizer with intelligent features: * - Query complexity analysis (depth, breadth, field count) * - Optimization suggestions (fragment extraction, field reduction) * - Response caching with query fingerprinting * - Schema introspection caching * - Batched query detection * - N+1 query problem detection * - Token-optimized output */ import { CacheEngine } from '../../core/cache-engine.js'; import { TokenCounter } from '../../core/token-counter.js'; import { MetricsCollector } from '../../core/metrics.js'; interface SmartGraphQLOptions { /** * GraphQL query to analyze */ query: string; /** * Query variables (optional) */ variables?: Record; /** * Operation name (optional) */ operationName?: string; /** * GraphQL endpoint for schema introspection (optional) */ endpoint?: string; /** * Enable complexity analysis (default: true) */ analyzeComplexity?: boolean; /** * Detect N+1 query problems (default: true) */ detectN1?: boolean; /** * Suggest query optimizations (default: true) */ suggestOptimizations?: boolean; /** * Force fresh analysis (bypass cache) */ force?: boolean; /** * Cache TTL in seconds (default: 300 = 5 minutes) */ ttl?: number; } interface ComplexityMetrics { depth: number; breadth: number; fieldCount: number; score: number; } interface FragmentSuggestion { name: string; fields: string[]; usage: number; reason: string; } interface FieldReduction { field: string; reason: string; impact: 'high' | 'medium' | 'low'; } interface BatchOpportunity { queries: string[]; reason: string; estimatedSavings: string; } interface N1Problem { field: string; location: string; severity: 'high' | 'medium' | 'low'; suggestion: string; } interface QueryAnalysis { operation: 'query' | 'mutation' | 'subscription'; name?: string; fields: string[]; complexity: ComplexityMetrics; } interface Optimizations { fragmentSuggestions: FragmentSuggestion[]; fieldReductions: FieldReduction[]; batchOpportunities: BatchOpportunity[]; n1Problems: N1Problem[]; } interface SchemaInfo { types: number; queries: number; mutations: number; subscriptions: number; } interface SmartGraphQLResult { query: QueryAnalysis; optimizations?: Optimizations; schema?: SchemaInfo; cached: boolean; metrics: { originalTokens: number; compactedTokens: number; reductionPercentage: number; }; } export declare class SmartGraphQL { private cache; private tokenCounter; private metrics; constructor(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector); run(options: SmartGraphQLOptions): Promise; private analyzeQuery; private parseQuery; private extractFragments; private parseSelections; private findNestedSelections; private calculateComplexity; private extractFields; private detectFragmentOpportunities; private detectFieldReductions; private getSelectionDepth; private detectBatchOpportunities; private detectN1Problems; private introspectSchema; private transformOutput; private generateCacheKey; private getCachedResult; private cacheResult; } export declare function getSmartGraphQL(cache: CacheEngine, tokenCounter: TokenCounter, metrics: MetricsCollector): SmartGraphQL; export declare function runSmartGraphQL(options: SmartGraphQLOptions): Promise; export declare const SMART_GRAPHQL_TOOL_DEFINITION: { name: string; description: string; inputSchema: { type: "object"; properties: { query: { type: "string"; description: string; }; variables: { type: "object"; description: string; }; operationName: { type: "string"; description: string; }; endpoint: { type: "string"; description: string; }; analyzeComplexity: { type: "boolean"; description: string; }; detectN1: { type: "boolean"; description: string; }; suggestOptimizations: { type: "boolean"; description: string; }; force: { type: "boolean"; description: string; }; ttl: { type: "number"; description: string; }; }; required: string[]; }; }; export type { SmartGraphQLOptions, SmartGraphQLResult, ComplexityMetrics, FragmentSuggestion, FieldReduction, BatchOpportunity, N1Problem, QueryAnalysis, Optimizations, SchemaInfo, }; //# sourceMappingURL=smart-graphql.d.ts.map