oxirs-gql 0.2.4

GraphQL façade for OxiRS with automatic schema generation from RDF ontologies
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
//! Federation Schema Validation
//!
//! This module provides comprehensive validation for federated GraphQL schemas,
//! ensuring consistency, correctness, and adherence to Apollo Federation specifications.
//!
//! ## Features
//!
//! - **Schema Composition Validation**: Validates schema stitching and composition
//! - **Entity Validation**: Ensures @key directives and entity resolution
//! - **Field Conflict Detection**: Identifies conflicting field definitions
//! - **Type Compatibility**: Validates type consistency across subgraphs
//! - **Directive Validation**: Checks Federation-specific directives
//! - **Circular Reference Detection**: Prevents circular dependencies

use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};

/// Validation severity level
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub enum ValidationSeverity {
    /// Critical error that prevents federation
    Error,
    /// Warning that should be addressed
    Warning,
    /// Informational notice
    Info,
}

/// Validation issue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationIssue {
    /// Severity level
    pub severity: ValidationSeverity,
    /// Issue code (e.g., "FIELD_CONFLICT", "MISSING_KEY")
    pub code: String,
    /// Human-readable message
    pub message: String,
    /// Location in schema (subgraph name, type, field)
    pub location: ValidationLocation,
    /// Suggested fix (if any)
    pub suggestion: Option<String>,
}

impl ValidationIssue {
    pub fn error(code: String, message: String, location: ValidationLocation) -> Self {
        Self {
            severity: ValidationSeverity::Error,
            code,
            message,
            location,
            suggestion: None,
        }
    }

    pub fn warning(code: String, message: String, location: ValidationLocation) -> Self {
        Self {
            severity: ValidationSeverity::Warning,
            code,
            message,
            location,
            suggestion: None,
        }
    }

    pub fn info(code: String, message: String, location: ValidationLocation) -> Self {
        Self {
            severity: ValidationSeverity::Info,
            code,
            message,
            location,
            suggestion: None,
        }
    }

    pub fn with_suggestion(mut self, suggestion: String) -> Self {
        self.suggestion = Some(suggestion);
        self
    }
}

/// Location of validation issue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationLocation {
    /// Subgraph name
    pub subgraph: String,
    /// Type name
    pub type_name: Option<String>,
    /// Field name
    pub field_name: Option<String>,
    /// Directive name
    pub directive_name: Option<String>,
}

impl ValidationLocation {
    pub fn subgraph(name: String) -> Self {
        Self {
            subgraph: name,
            type_name: None,
            field_name: None,
            directive_name: None,
        }
    }

    pub fn type_location(subgraph: String, type_name: String) -> Self {
        Self {
            subgraph,
            type_name: Some(type_name),
            field_name: None,
            directive_name: None,
        }
    }

    pub fn field_location(subgraph: String, type_name: String, field_name: String) -> Self {
        Self {
            subgraph,
            type_name: Some(type_name),
            field_name: Some(field_name),
            directive_name: None,
        }
    }
}

/// Validation result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationResult {
    /// All validation issues
    pub issues: Vec<ValidationIssue>,
    /// Whether validation passed (no errors)
    pub is_valid: bool,
    /// Number of errors
    pub error_count: usize,
    /// Number of warnings
    pub warning_count: usize,
}

impl ValidationResult {
    pub fn new() -> Self {
        Self {
            issues: Vec::new(),
            is_valid: true,
            error_count: 0,
            warning_count: 0,
        }
    }

    pub fn add_issue(&mut self, issue: ValidationIssue) {
        match issue.severity {
            ValidationSeverity::Error => {
                self.error_count += 1;
                self.is_valid = false;
            }
            ValidationSeverity::Warning => {
                self.warning_count += 1;
            }
            ValidationSeverity::Info => {}
        }
        self.issues.push(issue);
    }

    pub fn has_errors(&self) -> bool {
        self.error_count > 0
    }

    pub fn has_warnings(&self) -> bool {
        self.warning_count > 0
    }

    pub fn merge(&mut self, other: ValidationResult) {
        for issue in other.issues {
            self.add_issue(issue);
        }
    }
}

impl Default for ValidationResult {
    fn default() -> Self {
        Self::new()
    }
}

/// GraphQL type definition (simplified)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeDefinition {
    pub name: String,
    pub kind: TypeKind,
    pub fields: Vec<FieldDefinition>,
    pub directives: Vec<DirectiveDefinition>,
    pub interfaces: Vec<String>,
}

/// Type kind
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
pub enum TypeKind {
    Object,
    Interface,
    Union,
    Enum,
    InputObject,
    Scalar,
}

/// Field definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldDefinition {
    pub name: String,
    pub type_name: String,
    pub is_list: bool,
    pub is_non_null: bool,
    pub arguments: Vec<ArgumentDefinition>,
    pub directives: Vec<DirectiveDefinition>,
}

/// Argument definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ArgumentDefinition {
    pub name: String,
    pub type_name: String,
    pub is_non_null: bool,
    pub default_value: Option<String>,
}

/// Directive definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DirectiveDefinition {
    pub name: String,
    pub arguments: HashMap<String, String>,
}

/// Subgraph schema
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubgraphSchema {
    pub name: String,
    pub types: HashMap<String, TypeDefinition>,
}

/// Federation schema validator
pub struct FederationSchemaValidator {
    /// Federation-specific directives
    federation_directives: HashSet<String>,
}

impl FederationSchemaValidator {
    pub fn new() -> Self {
        let mut federation_directives = HashSet::new();
        federation_directives.insert("key".to_string());
        federation_directives.insert("requires".to_string());
        federation_directives.insert("provides".to_string());
        federation_directives.insert("external".to_string());
        federation_directives.insert("extends".to_string());
        federation_directives.insert("shareable".to_string());
        federation_directives.insert("inaccessible".to_string());
        federation_directives.insert("override".to_string());
        federation_directives.insert("tag".to_string());

        Self {
            federation_directives,
        }
    }

    /// Validate multiple subgraph schemas
    pub fn validate(&self, subgraphs: &[SubgraphSchema]) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Validate individual subgraphs
        for subgraph in subgraphs {
            result.merge(self.validate_subgraph(subgraph));
        }

        // Cross-subgraph validation
        result.merge(self.validate_entity_keys(subgraphs));
        result.merge(self.validate_field_conflicts(subgraphs));
        result.merge(self.validate_type_consistency(subgraphs));
        result.merge(self.validate_circular_references(subgraphs));

        result
    }

    /// Validate a single subgraph
    fn validate_subgraph(&self, subgraph: &SubgraphSchema) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Check for reserved type names
        for type_name in subgraph.types.keys() {
            if self.is_reserved_type_name(type_name) {
                result.add_issue(
                    ValidationIssue::error(
                        "RESERVED_TYPE_NAME".to_string(),
                        format!("Type name '{}' is reserved", type_name),
                        ValidationLocation::type_location(subgraph.name.clone(), type_name.clone()),
                    )
                    .with_suggestion(
                        "Use a different type name that doesn't conflict with GraphQL built-ins"
                            .to_string(),
                    ),
                );
            }
        }

        // Validate each type
        for (type_name, type_def) in &subgraph.types {
            result.merge(self.validate_type(subgraph, type_name, type_def));
        }

        result
    }

    /// Validate a type definition
    fn validate_type(
        &self,
        subgraph: &SubgraphSchema,
        type_name: &str,
        type_def: &TypeDefinition,
    ) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Validate fields
        for field in &type_def.fields {
            result.merge(self.validate_field(subgraph, type_name, field));
        }

        // Validate directives
        for directive in &type_def.directives {
            if !self.is_valid_directive(&directive.name) {
                result.add_issue(ValidationIssue::warning(
                    "UNKNOWN_DIRECTIVE".to_string(),
                    format!("Unknown directive '@{}'", directive.name),
                    ValidationLocation::type_location(subgraph.name.clone(), type_name.to_string()),
                ));
            }
        }

        result
    }

    /// Validate a field definition
    fn validate_field(
        &self,
        subgraph: &SubgraphSchema,
        type_name: &str,
        field: &FieldDefinition,
    ) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Check if field type exists (if not a built-in)
        if !self.is_builtin_type(&field.type_name) && !subgraph.types.contains_key(&field.type_name)
        {
            result.add_issue(
                ValidationIssue::error(
                    "UNKNOWN_TYPE".to_string(),
                    format!(
                        "Field '{}' references unknown type '{}'",
                        field.name, field.type_name
                    ),
                    ValidationLocation::field_location(
                        subgraph.name.clone(),
                        type_name.to_string(),
                        field.name.clone(),
                    ),
                )
                .with_suggestion(format!(
                    "Define type '{}' or import it from another subgraph",
                    field.type_name
                )),
            );
        }

        // Validate field directives
        for directive in &field.directives {
            if directive.name == "external" {
                // @external fields should not have resolvers in this subgraph
                result.add_issue(ValidationIssue::info(
                    "EXTERNAL_FIELD".to_string(),
                    format!("Field '{}' is marked as @external", field.name),
                    ValidationLocation::field_location(
                        subgraph.name.clone(),
                        type_name.to_string(),
                        field.name.clone(),
                    ),
                ));
            }
        }

        result
    }

    /// Validate entity @key directives
    fn validate_entity_keys(&self, subgraphs: &[SubgraphSchema]) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Find all entities (types with @key directive)
        for subgraph in subgraphs {
            for (type_name, type_def) in &subgraph.types {
                let has_key = type_def.directives.iter().any(|d| d.name == "key");

                if has_key {
                    // Validate @key fields exist
                    for directive in &type_def.directives {
                        if directive.name == "key" {
                            if let Some(fields) = directive.arguments.get("fields") {
                                result.merge(
                                    self.validate_key_fields(subgraph, type_name, type_def, fields),
                                );
                            } else {
                                result.add_issue(ValidationIssue::error(
                                    "MISSING_KEY_FIELDS".to_string(),
                                    "@key directive must specify fields".to_string(),
                                    ValidationLocation::type_location(
                                        subgraph.name.clone(),
                                        type_name.clone(),
                                    ),
                                ));
                            }
                        }
                    }
                }
            }
        }

        result
    }

    /// Validate @key fields
    fn validate_key_fields(
        &self,
        subgraph: &SubgraphSchema,
        type_name: &str,
        type_def: &TypeDefinition,
        key_fields: &str,
    ) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Parse key fields (simplified - in production, use proper parsing)
        let fields: Vec<&str> = key_fields.split_whitespace().collect();

        for field_name in fields {
            // Check if field exists
            let field_exists = type_def.fields.iter().any(|f| f.name == field_name);

            if !field_exists {
                result.add_issue(
                    ValidationIssue::error(
                        "KEY_FIELD_NOT_FOUND".to_string(),
                        format!(
                            "@key references non-existent field '{}' on type '{}'",
                            field_name, type_name
                        ),
                        ValidationLocation::type_location(
                            subgraph.name.clone(),
                            type_name.to_string(),
                        ),
                    )
                    .with_suggestion(format!(
                        "Add field '{}' to type '{}'",
                        field_name, type_name
                    )),
                );
            }
        }

        result
    }

    /// Validate field conflicts across subgraphs
    fn validate_field_conflicts(&self, subgraphs: &[SubgraphSchema]) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Build a map of types to their fields across subgraphs
        let mut type_fields: HashMap<String, Vec<(String, FieldDefinition)>> = HashMap::new();

        for subgraph in subgraphs {
            for (type_name, type_def) in &subgraph.types {
                for field in &type_def.fields {
                    type_fields
                        .entry(type_name.clone())
                        .or_default()
                        .push((subgraph.name.clone(), field.clone()));
                }
            }
        }

        // Check for conflicts
        for (type_name, fields) in type_fields {
            let mut field_map: HashMap<String, Vec<(String, FieldDefinition)>> = HashMap::new();

            for (subgraph_name, field) in fields {
                field_map
                    .entry(field.name.clone())
                    .or_default()
                    .push((subgraph_name, field));
            }

            for (field_name, definitions) in field_map {
                if definitions.len() > 1 {
                    // Check if definitions are compatible
                    let first = &definitions[0].1;

                    for (subgraph_name, def) in &definitions[1..] {
                        if !self.are_fields_compatible(first, def) {
                            result.add_issue(ValidationIssue::error(
                                "FIELD_CONFLICT".to_string(),
                                format!(
                                    "Field '{}' on type '{}' has conflicting definitions in subgraphs '{}' and '{}'",
                                    field_name, type_name, definitions[0].0, subgraph_name
                                ),
                                ValidationLocation::field_location(
                                    subgraph_name.clone(),
                                    type_name.clone(),
                                    field_name.clone(),
                                ),
                            ).with_suggestion("Use @shareable directive or make field types consistent".to_string()));
                        }
                    }
                }
            }
        }

        result
    }

    /// Check if two field definitions are compatible
    fn are_fields_compatible(&self, field1: &FieldDefinition, field2: &FieldDefinition) -> bool {
        field1.type_name == field2.type_name
            && field1.is_list == field2.is_list
            && field1.is_non_null == field2.is_non_null
    }

    /// Validate type consistency
    fn validate_type_consistency(&self, subgraphs: &[SubgraphSchema]) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Check that extended types exist
        for subgraph in subgraphs {
            for (type_name, type_def) in &subgraph.types {
                let extends = type_def.directives.iter().any(|d| d.name == "extends");

                if extends {
                    // Check if type is defined in another subgraph
                    let defined_elsewhere = subgraphs
                        .iter()
                        .any(|s| s.name != subgraph.name && s.types.contains_key(type_name));

                    if !defined_elsewhere {
                        result.add_issue(ValidationIssue::error(
                            "EXTENDS_UNDEFINED_TYPE".to_string(),
                            format!(
                                "Type '{}' extends a type that is not defined in any subgraph",
                                type_name
                            ),
                            ValidationLocation::type_location(
                                subgraph.name.clone(),
                                type_name.clone(),
                            ),
                        ));
                    }
                }
            }
        }

        result
    }

    /// Validate circular references
    fn validate_circular_references(&self, subgraphs: &[SubgraphSchema]) -> ValidationResult {
        let mut result = ValidationResult::new();

        // Build dependency graph
        let mut dependencies: HashMap<String, HashSet<String>> = HashMap::new();

        for subgraph in subgraphs {
            for (type_name, type_def) in &subgraph.types {
                let mut deps = HashSet::new();

                for field in &type_def.fields {
                    deps.insert(field.type_name.clone());
                }

                dependencies.insert(type_name.clone(), deps);
            }
        }

        // Check for cycles using DFS
        for type_name in dependencies.keys() {
            if Self::has_circular_dependency(type_name, &dependencies, &mut HashSet::new()) {
                result.add_issue(
                    ValidationIssue::warning(
                        "CIRCULAR_REFERENCE".to_string(),
                        format!("Type '{}' has circular dependencies", type_name),
                        ValidationLocation::type_location("*".to_string(), type_name.clone()),
                    )
                    .with_suggestion(
                        "Circular references are allowed but may impact performance".to_string(),
                    ),
                );
            }
        }

        result
    }

    /// Check for circular dependency using DFS
    fn has_circular_dependency(
        type_name: &str,
        dependencies: &HashMap<String, HashSet<String>>,
        visited: &mut HashSet<String>,
    ) -> bool {
        if visited.contains(type_name) {
            return true;
        }

        visited.insert(type_name.to_string());

        if let Some(deps) = dependencies.get(type_name) {
            for dep in deps {
                if Self::has_circular_dependency(dep, dependencies, &mut visited.clone()) {
                    return true;
                }
            }
        }

        false
    }

    /// Check if type name is reserved
    fn is_reserved_type_name(&self, name: &str) -> bool {
        matches!(
            name,
            "Query"
                | "Mutation"
                | "Subscription"
                | "__Schema"
                | "__Type"
                | "__Field"
                | "__InputValue"
                | "__EnumValue"
                | "__Directive"
        )
    }

    /// Check if type is a built-in GraphQL type
    fn is_builtin_type(&self, name: &str) -> bool {
        matches!(
            name,
            "String" | "Int" | "Float" | "Boolean" | "ID" | "DateTime"
        )
    }

    /// Check if directive is valid
    fn is_valid_directive(&self, name: &str) -> bool {
        self.federation_directives.contains(name)
            || matches!(name, "deprecated" | "skip" | "include" | "specifiedBy")
    }
}

impl Default for FederationSchemaValidator {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn create_test_type(name: &str) -> TypeDefinition {
        TypeDefinition {
            name: name.to_string(),
            kind: TypeKind::Object,
            fields: vec![],
            directives: vec![],
            interfaces: vec![],
        }
    }

    #[test]
    fn test_validation_issue_creation() {
        let location = ValidationLocation::subgraph("test_subgraph".to_string());

        let error = ValidationIssue::error(
            "TEST_ERROR".to_string(),
            "Test error message".to_string(),
            location.clone(),
        );

        assert_eq!(error.severity, ValidationSeverity::Error);
        assert_eq!(error.code, "TEST_ERROR");
    }

    #[test]
    fn test_validation_result() {
        let mut result = ValidationResult::new();
        assert!(result.is_valid);
        assert_eq!(result.error_count, 0);

        let error = ValidationIssue::error(
            "ERROR".to_string(),
            "Error".to_string(),
            ValidationLocation::subgraph("test".to_string()),
        );

        result.add_issue(error);
        assert!(!result.is_valid);
        assert_eq!(result.error_count, 1);
    }

    #[test]
    fn test_validator_creation() {
        let validator = FederationSchemaValidator::new();
        assert!(validator.federation_directives.contains("key"));
        assert!(validator.federation_directives.contains("external"));
    }

    #[test]
    fn test_is_reserved_type_name() {
        let validator = FederationSchemaValidator::new();

        assert!(validator.is_reserved_type_name("Query"));
        assert!(validator.is_reserved_type_name("Mutation"));
        assert!(!validator.is_reserved_type_name("User"));
    }

    #[test]
    fn test_is_builtin_type() {
        let validator = FederationSchemaValidator::new();

        assert!(validator.is_builtin_type("String"));
        assert!(validator.is_builtin_type("Int"));
        assert!(!validator.is_builtin_type("User"));
    }

    #[test]
    fn test_validate_empty_subgraphs() {
        let validator = FederationSchemaValidator::new();
        let result = validator.validate(&[]);

        assert!(result.is_valid);
        assert_eq!(result.issues.len(), 0);
    }

    #[test]
    fn test_validate_single_subgraph() {
        let validator = FederationSchemaValidator::new();

        let mut types = HashMap::new();
        types.insert("User".to_string(), create_test_type("User"));

        let subgraph = SubgraphSchema {
            name: "users".to_string(),
            types,
        };

        let result = validator.validate(&[subgraph]);
        assert!(result.is_valid);
    }

    #[test]
    fn test_validate_reserved_type_name() {
        let validator = FederationSchemaValidator::new();

        let mut types = HashMap::new();
        types.insert("Query".to_string(), create_test_type("Query"));

        let subgraph = SubgraphSchema {
            name: "test".to_string(),
            types,
        };

        let result = validator.validate(&[subgraph]);
        assert!(!result.is_valid);
        assert_eq!(result.error_count, 1);
        assert_eq!(result.issues[0].code, "RESERVED_TYPE_NAME");
    }

    #[test]
    fn test_field_compatibility() {
        let validator = FederationSchemaValidator::new();

        let field1 = FieldDefinition {
            name: "id".to_string(),
            type_name: "ID".to_string(),
            is_list: false,
            is_non_null: true,
            arguments: vec![],
            directives: vec![],
        };

        let field2 = FieldDefinition {
            name: "id".to_string(),
            type_name: "ID".to_string(),
            is_list: false,
            is_non_null: true,
            arguments: vec![],
            directives: vec![],
        };

        assert!(validator.are_fields_compatible(&field1, &field2));

        let field3 = FieldDefinition {
            name: "id".to_string(),
            type_name: "String".to_string(),
            is_list: false,
            is_non_null: true,
            arguments: vec![],
            directives: vec![],
        };

        assert!(!validator.are_fields_compatible(&field1, &field3));
    }

    #[test]
    fn test_validation_severity() {
        assert_eq!(ValidationSeverity::Error, ValidationSeverity::Error);
        assert_ne!(ValidationSeverity::Error, ValidationSeverity::Warning);
    }

    #[test]
    fn test_type_kind_variants() {
        assert_eq!(TypeKind::Object, TypeKind::Object);
        assert_ne!(TypeKind::Object, TypeKind::Interface);
    }
}