UNPKG

graphql-mandatory-validator

Version:

A GraphQL schema validator for mandatory fields with default values and composite type validation

99 lines 2.85 kB
export interface ValidationOptions { /** * Base directory to search for GraphQL files (default: 'src/type-defs') */ baseDir?: string; /** * Custom scalar type defaults */ scalarDefaults?: Record<string, string>; /** * Whether to use colored output (default: true) */ colorOutput?: boolean; /** * Whether to exit process on validation failure (default: true) */ exitOnError?: boolean; } export interface ValidationResult { success: boolean; errors: ValidationError[]; filesChecked: number; } export interface ValidationError { file: string; line: number; fieldName: string; fieldType: string; expectedDefault?: string; message: string; errorType: 'missing-default' | 'empty-composite' | 'missing-enum-default' | 'invalid-enum-default'; } export declare class GraphQLValidator { private options; constructor(options?: ValidationOptions); /** * Get staged .graphql files from git */ getStagedGraphqlFiles(): string[]; /** * Get all .graphql files in the base directory */ getAllGraphqlFiles(projectRoot?: string): string[]; /** * Validate newly added mandatory fields in staged files */ validateStagedFiles(): Promise<ValidationResult>; /** * Validate all GraphQL files in the project */ validateProject(projectRoot?: string): Promise<ValidationResult>; /** * Parse git diff to extract added lines with correct line numbers */ private parseGitDiffForAddedLines; /** * Parse GraphQL schema from files to understand type definitions */ private parseGraphQLSchema; /** * Parse a single GraphQL file using GraphQL AST parser */ private parseFileSchema; /** * Extract type name from GraphQL AST type node */ private extractTypeFromAST; /** * Get line number from GraphQL AST location */ private getLineNumberFromLocation; /** * Fallback regex-based parsing for when AST parsing fails */ private parseFileSchemeFallback; /** * Validate composite fields using AST-based approach with line filtering */ private validateCompositeFields; /** * Validate that mandatory composite types have at least one mandatory field * Only checks newly added fields when onlyDiffChanges is true */ private validateCompositeTypes; /** * Validate specific GraphQL files using AST-based approach */ private validateFiles; /** * Report validation results */ private reportResults; /** * Run validation (convenience method for CLI usage) */ run(mode?: 'staged' | 'all', projectRoot?: string): Promise<ValidationResult>; } export default GraphQLValidator; //# sourceMappingURL=index.d.ts.map