validate method
void
validate()
Validates the schema context for consistency
Implementation
void validate() {
if (schema.definitions.isEmpty) {
throw SchemaContextValidationException(
'Schema must contain at least one definition',
);
}
// Validate that the type visitor has been properly initialized
if (typeVisitor.types.isEmpty) {
throw SchemaContextValidationException(
'Type visitor must be initialized with schema types',
);
}
// Validate that basic scalar types are present
final requiredScalars = ['Boolean', 'Float', 'ID', 'Int', 'String'];
for (final scalar in requiredScalars) {
if (!typeVisitor.types.containsKey(scalar)) {
throw SchemaContextValidationException(
'Missing required scalar type: $scalar',
);
}
}
// Validate that schema definitions match type visitor types
final schemaTypeNames = schema.definitions
.whereType<TypeDefinitionNode>()
.map((node) => node.name.value)
.toSet();
final visitorTypeNames = typeVisitor.types.keys
.where((name) => !requiredScalars.contains(name))
.toSet();
if (!schemaTypeNames.containsAll(
visitorTypeNames.difference(requiredScalars.toSet()),
)) {
throw SchemaContextValidationException(
'Type visitor contains types not found in schema',
);
}
}