UNPKG

deepsource-mcp-server

Version:
121 lines (120 loc) 3.07 kB
/** * @fileoverview GraphQL Query Builder for constructing type-safe queries * * This module provides a fluent API for building GraphQL queries with: * - Type safety for fields and arguments * - Automatic fragment generation * - Query optimization * - Reusable field selections */ import { ProjectKey, RunId } from '../../types/branded.js'; /** * GraphQL field selection */ export interface FieldSelection { name: string; alias?: string; args?: Record<string, unknown>; fields?: FieldSelection[]; } /** * GraphQL fragment definition */ export interface Fragment { name: string; type: string; fields: FieldSelection[]; } /** * Query operation type */ export type OperationType = 'query' | 'mutation' | 'subscription'; /** * GraphQL query builder for constructing type-safe queries */ export declare class GraphQLQueryBuilder { private operation; private operationName?; private variables; private selections; private fragments; /** * Creates a new query builder * @param operation - The operation type (default: 'query') */ constructor(operation?: OperationType); /** * Sets the operation name */ withName(name: string): this; /** * Adds a variable to the query */ withVariable(name: string, type: string, value: unknown): this; /** * Adds a field selection */ select(field: string | FieldSelection): this; /** * Adds multiple field selections */ selectMany(...fields: (string | FieldSelection)[]): this; /** * Adds a nested field selection */ selectNested(name: string, fields: (string | FieldSelection)[], args?: Record<string, unknown>): this; /** * Adds a fragment */ withFragment(fragment: Fragment): this; /** * Uses a fragment in the selection */ useFragment(fragmentName: string): this; /** * Builds the query string */ build(): { query: string; variables: Record<string, unknown>; }; /** * Builds variable declarations */ private buildVariableDeclarations; /** * Builds a selection set */ private buildSelectionSet; /** * Builds argument string */ private static buildArguments; /** * Builds fragment definitions */ private buildFragments; /** * Static factory methods for common queries */ /** * Creates a query builder for fetching projects */ static projects(): GraphQLQueryBuilder; /** * Creates a query builder for fetching a specific run */ static run(projectKey: ProjectKey, runId: RunId): GraphQLQueryBuilder; /** * Creates a query builder for fetching quality metrics */ static qualityMetrics(projectKey: ProjectKey): GraphQLQueryBuilder; /** * Creates a reusable fragment for issue fields */ static issueFieldsFragment(): Fragment; /** * Creates a reusable fragment for run fields */ static runFieldsFragment(): Fragment; }