/** * GraphQL Introspection Module * * Automatically discovers and queries GraphQL schemas to generate * API patterns without requiring observation-based learning. * * This module: * 1. Probes common GraphQL endpoint locations * 2. Executes introspection queries to discover schema * 3. Parses schema to extract types, queries, mutations * 4. Generates query templates for common operations */ /** * GraphQL type kind as returned by introspection */ export type GraphQLTypeKind = 'SCALAR' | 'OBJECT' | 'INTERFACE' | 'UNION' | 'ENUM' | 'INPUT_OBJECT' | 'LIST' | 'NON_NULL'; /** * GraphQL type reference (used for field types, arg types, etc.) */ export interface GraphQLTypeRef { name: string | null; kind: GraphQLTypeKind; ofType?: GraphQLTypeRef | null; } /** * GraphQL field argument */ export interface GraphQLArgument { name: string; type: GraphQLTypeRef; description?: string; defaultValue?: string; } /** * GraphQL field definition */ export interface GraphQLField { name: string; description?: string; args: GraphQLArgument[]; type: GraphQLTypeRef; } /** * GraphQL type definition */ export interface GraphQLType { name: string; kind: GraphQLTypeKind; description?: string; fields?: GraphQLField[] | null; inputFields?: GraphQLArgument[] | null; enumValues?: Array<{ name: string; description?: string; }> | null; interfaces?: Array<{ name: string; }> | null; possibleTypes?: Array<{ name: string; }> | null; } /** * Introspection query result */ export interface IntrospectionResult { __schema: { types: GraphQLType[]; queryType: { name: string; } | null; mutationType: { name: string; } | null; subscriptionType: { name: string; } | null; }; } /** * Parsed GraphQL schema */ export interface ParsedGraphQLSchema { /** Endpoint URL where schema was discovered */ endpoint: string; /** Query type name */ queryTypeName: string | null; /** Mutation type name */ mutationTypeName: string | null; /** Subscription type name */ subscriptionTypeName: string | null; /** All types in the schema */ types: Map; /** Entity types (non-built-in object types) */ entityTypes: string[]; /** Detected pagination patterns */ paginationPattern: PaginationPattern | null; /** When this schema was fetched */ fetchedAt: number; } /** * Pagination pattern detected in the schema */ export type PaginationPattern = 'relay' | 'offset' | 'cursor' | 'page'; /** * Generated GraphQL query pattern */ export interface GraphQLQueryPattern { /** Unique identifier */ id: string; /** The query name */ queryName: string; /** The GraphQL operation type */ operationType: 'query' | 'mutation' | 'subscription'; /** The entity type this query returns */ returnType: string; /** Required arguments */ requiredArgs: GraphQLArgument[]; /** Optional arguments */ optionalArgs: GraphQLArgument[]; /** Default field selection */ defaultFieldSelection: string[]; /** Generated query template */ queryTemplate: string; /** Confidence score (0-1) */ confidence: number; } /** * GraphQL discovery result */ export interface GraphQLDiscoveryResult { /** Whether GraphQL was discovered */ found: boolean; /** The GraphQL endpoint URL */ endpoint?: string; /** Parsed schema (if introspection succeeded) */ schema?: ParsedGraphQLSchema; /** Generated query patterns */ patterns?: GraphQLQueryPattern[]; /** Error message if discovery failed */ error?: string; /** Whether introspection is disabled */ introspectionDisabled?: boolean; } /** * Common GraphQL endpoint paths to probe */ export declare const GRAPHQL_ENDPOINT_PATHS: string[]; /** * The introspection query to discover schema */ export declare const INTROSPECTION_QUERY = "\nquery IntrospectionQuery {\n __schema {\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n name\n kind\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n name\n description\n type {\n name\n kind\n ofType {\n name\n kind\n ofType {\n name\n kind\n ofType {\n name\n kind\n }\n }\n }\n }\n defaultValue\n }\n type {\n name\n kind\n ofType {\n name\n kind\n ofType {\n name\n kind\n ofType {\n name\n kind\n }\n }\n }\n }\n }\n inputFields {\n name\n description\n type {\n name\n kind\n ofType {\n name\n kind\n }\n }\n defaultValue\n }\n enumValues(includeDeprecated: true) {\n name\n description\n }\n interfaces {\n name\n }\n possibleTypes {\n name\n }\n }\n }\n}\n"; /** * Simple introspection query (for endpoints with limited introspection) */ export declare const SIMPLE_INTROSPECTION_QUERY = "\nquery {\n __schema {\n queryType { name }\n mutationType { name }\n types {\n name\n kind\n fields { name type { name kind ofType { name kind } } }\n }\n }\n}\n"; /** * Probe a domain for GraphQL endpoints */ export declare function probeGraphQLEndpoints(domain: string, fetchFn?: (url: string, options: RequestInit) => Promise): Promise; /** * Check if a URL is a GraphQL endpoint */ export declare function isGraphQLEndpoint(url: string): boolean; /** * Execute introspection query on a GraphQL endpoint */ export declare function executeIntrospection(endpoint: string, headers?: Record, fetchFn?: (url: string, options: RequestInit) => Promise): Promise; /** * Parse introspection result into a structured schema */ export declare function parseSchema(endpoint: string, introspection: IntrospectionResult): ParsedGraphQLSchema; /** * Get the base type name from a potentially wrapped type */ export declare function getBaseTypeName(typeRef: GraphQLTypeRef): string; /** * Check if a type is non-null (required) */ export declare function isNonNull(typeRef: GraphQLTypeRef): boolean; /** * Check if a type is a list */ export declare function isList(typeRef: GraphQLTypeRef): boolean; /** * Generate query patterns from parsed schema */ export declare function generateQueryPatterns(schema: ParsedGraphQLSchema): GraphQLQueryPattern[]; /** * Discover GraphQL API for a domain */ export declare function discoverGraphQL(domain: string, options?: { headers?: Record; fetchFn?: (url: string, options: RequestInit) => Promise; specificEndpoint?: string; }): Promise; /** * Check if a domain likely has GraphQL based on known indicators */ export declare function isLikelyGraphQL(domain: string): boolean; //# sourceMappingURL=graphql-introspection.d.ts.map