graphql-mandatory-validator
Version:
A GraphQL schema validator using AST-only parsing for mandatory fields with default values, array validation, and composite type validation
144 lines (110 loc) • 6 kB
Markdown
# Changelog
All notable changes to this project will be documented in this file.
## [1.3.2] - 2025-09-18
### Fixed
- 🐛 **EXTEND TYPE SUPPORT**: Added validation support for `extend type` definitions
- Fixed issue where mandatory fields in `extend type` blocks were not being validated
- Enhanced AST parser to handle both `ObjectTypeDefinitionNode` and `ObjectTypeExtensionNode`
## [1.3.1] - 2025-09-12
### Fixed
- 🐛 **BUG FIX**: Fixed enum validation to properly validate unquoted enum values
- Validator now correctly catches typos in unquoted enum default values like `@defaultValue(value: Falsase)`
- Added support for `Kind.ENUM` AST nodes in default value extraction
- Added test case to prevent regression of unquoted enum validation
## [1.3.0] - 2025-09-12
### Added
- 🌐 **NEW FEATURE**: Cross-file enum validation for mandatory enum fields
- Validates enum fields even when the enum is defined in a different file
- Scans all GraphQL files in the project to build a complete enum registry
- Ensures mandatory enum fields have valid default values from their enum definition
- Prevents 5xx errors in schema-only deployments due to missing enum defaults
### Improved
- Enhanced schema parsing with two-pass approach for better cross-file type detection
- Added `parseEnumsFromFile()` method for efficient enum extraction
- Optimized validation to maintain backward compatibility with existing features
- Comprehensive test coverage for cross-file enum scenarios
## [1.1.2] - 2025-01-17
### Fixed
- 🚨 **CRITICAL**: Fixed staged mode validation bug where all lines were being validated instead of only newly added lines
- Fixed git diff parsing to correctly extract line numbers from diff hunks
- Fixed content trimming in scalar and composite validation
- Staged mode now properly ignores existing schema issues and only validates new changes
- Added comprehensive test suite to verify all validation features work correctly
## [1.1.1] - 2025-01-17
### Fixed
- 🐛 **CRITICAL**: Fixed enum validation incorrectly treating composite types as enums
- Enum validation now properly distinguishes between composite and enum types
- Composite types are handled by composite validation, not enum validation
- Prevents false positive enum errors for composite types like `SetupFee!`
## [1.1.0] - 2025-01-16
### Added
- 🎯 **NEW FEATURE**: Enum type validation for mandatory enum fields
- Validates that mandatory enum fields have `@defaultValue` directives
- Suggests using `"UNKNOWN"` or any valid enum value as default
- Added `missing-enum-default` error type for better error categorization
### Improved
- Enhanced field validation logic to distinguish between scalar, composite, and enum types
- Better error messages with specific guidance for enum default values
- Comprehensive documentation with enum validation examples
### Changed
- Updated ValidationError interface to include `missing-enum-default` error type
- Improved validation flow to handle three types of mandatory fields: scalars, composites, and enums
## [1.0.4] - 2025-01-16
### Improved
- **Enhanced CLI help text with better examples and validation rule explanations**
- Added more comprehensive usage examples for different integration scenarios
- Improved documentation for lint-staged and CI/CD usage
## [1.0.3] - 2025-01-16
### Fixed
- **CRITICAL FIX**: Composite type validation now only checks newly added mandatory composite fields in staged mode
- Fixed issue where adding a new field would trigger validation errors for existing mandatory composite fields
- Composite validation now follows the same "only check new changes" principle as scalar validation
- Prevents false positives on existing composite type issues in the codebase
### Changed
- Improved `validateCompositeTypes` method to respect `onlyDiffChanges` parameter
- Enhanced staged mode validation to be more precise and developer-friendly
## [1.0.2] - 2025-01-16
### Fixed
- Removed internal repository URLs from package.json for cleaner public package metadata
## [1.0.1] - 2025-01-16
### Added
- Automated release scripts for easier version management
- `release:patch`, `release:minor`, `release:major` npm scripts
### Changed
- Improved release workflow documentation
## [1.0.0] - 2025-01-16
### Added
- 🎉 Initial release of GraphQL Validator
- ✅ Validates mandatory scalar fields have appropriate `@defaultValue` directives
- 🏗️ Validates mandatory composite types have at least one mandatory field
- 🔧 Configurable scalar type defaults (String, Int, Float, Boolean, ID)
- 📁 Works with standard `src/type-defs` directory structure
- 🚀 Support for both staged file validation (pre-commit) and full project validation
- 🎨 Colored terminal output with detailed error messages
- 📦 Available as both CLI tool and programmatic API
- 🔄 Cross-repository compatibility
### Features
#### Scalar Type Validation
- Enforces `@defaultValue` for all mandatory scalar fields
- Supports custom scalar type mappings
- Only validates newly added lines in staged mode
#### Composite Type Validation
- Ensures mandatory composite types contain at least one mandatory field
- Prevents meaningless mandatory constraints on empty composite types
- Smart validation that understands type relationships across files
#### CLI Tool
- `--mode staged|all` for different validation modes
- `--base-dir` for custom GraphQL directory paths
- `--no-color` and `--no-exit` flags for CI/CD integration
- Comprehensive help and usage examples
#### API
- `GraphQLValidator` class with full configuration options
- `validateStagedFiles()` and `validateProject()` methods
- Detailed error reporting with file paths and line numbers
- Support for custom validation options
### Default Scalar Mappings
- `String!` → `@defaultValue(value: "")`
- `Int!` → `@defaultValue(value: 0)`
- `Float!` → `@defaultValue(value: 0.0)`
- `Boolean!` → `@defaultValue(value: false)`
- `ID!` → `@defaultValue(value: "")`