Skip to content

[libgraphql-core-v1] Task 15: Validators (object/interface, union, input object, directive)#99

Merged
jeffmo merged 9 commits into
mainfrom
lgcore_v1_task15
Apr 12, 2026
Merged

[libgraphql-core-v1] Task 15: Validators (object/interface, union, input object, directive)#99
jeffmo merged 9 commits into
mainfrom
lgcore_v1_task15

Conversation

@jeffmo

@jeffmo jeffmo commented Apr 9, 2026

Copy link
Copy Markdown
Owner

Summary

Implements 4 type-system validators for cross-type validation of GraphQL schemas. These validators are designed to be called from SchemaBuilder::build() (Task 16) but are not yet wired into the build pipelinebuild() is currently todo!().

ObjectOrInterfaceTypeValidator

  • Generic over T: HasFieldsAndInterfaces — validates both ObjectType and InterfaceType
  • Three-phase interface validation: (1) completeness — implemented interfaces exist and are interface types, (2) field contracts — all interface fields present with compatible params, additional params must be optional, (3) field types — covariant return types
  • Precise error spans: interface-clause errors point at the interface reference span, not the whole type
  • Rich error notes: param type mismatches, required additional params, and return type mismatches all include notes pointing at the interface's definition
  • Output field types must be output types, param types must be input types
  • Edit-distance "did you mean?" suggestions on undefined-name errors

UnionTypeValidator

  • Members must exist in types_map and be Object types
  • Edit-distance "did you mean?" suggestions on undefined member names
  • Empty union check (EmptyUnionType) is a SchemaBuildErrorKind — will be added in build() (Task 16)

InputObjectTypeValidator

  • Fixed v0 bug: uses !is_input_type() instead of as_object().is_some() — now correctly rejects Interface and Union types as input field types
  • Circular non-nullable reference detection via recursive DFS; list types break circular chains per spec
  • Edit-distance "did you mean?" suggestions on undefined type references

DirectiveDefinitionValidator (NEW — absent in v0)

  • Validates custom directive parameter types are input types
  • Dedicated InvalidDirectiveParameterType error variant
  • Edit-distance "did you mean?" suggestions on undefined parameter type references

Removed: type_reference_validator

All type reference validation is distributed across the per-type validators — no separate pass needed.

Cross-cutting

  • All identifiers in error messages wrapped in backticks
  • All error pushes include spec-link notes
  • Precise spans: interface-clause errors use the interface reference span
  • Edit-distance "did you mean?" suggestions on all undefined-name errors

Note: Validators are not yet wired into SchemaBuilder::build() — that is Task 16.

Test plan

  • 194 total tests pass (cargo test --package libgraphql-core-v1)
  • Validator tests cover all error paths: undefined types, wrong type kinds, missing fields, param mismatches, return type covariance, circular input objects, directive param types
  • cargo clippy --tests --package libgraphql-core-v1 -- -D warnings clean
  • cargo check --tests --package libgraphql-core-v1 clean

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements cross-type schema validation in libgraphql-core-v1 during SchemaBuilder::build(), adding per-type validators for object/interface implementation rules, unions, input objects, and directive definitions.

Changes:

  • Added 4 validators (object/interface, union, input object, directive definition) plus comprehensive unit tests.
  • Updated type-validation error display formatting for circular input field chains (wrapping identifiers in backticks).
  • Exposed a new internal validators module and updated the implementation plan notes.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
libgraphql-core-v1-plan.md Marks validator work as completed and documents implementation notes.
crates/libgraphql-core-v1/src/lib.rs Adds internal validators module to the crate.
crates/libgraphql-core-v1/src/validators/mod.rs Declares validator submodules and re-exports validator entry points.
crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Validates interface implementation correctness and input/output type legality for fields/params.
crates/libgraphql-core-v1/src/validators/union_type_validator.rs Validates union member existence and member type-kind constraints.
crates/libgraphql-core-v1/src/validators/input_object_type_validator.rs Validates input field types and detects non-nullable circular input object reference chains.
crates/libgraphql-core-v1/src/validators/directive_definition_validator.rs Validates custom directive parameter types are input types.
crates/libgraphql-core-v1/src/validators/tests/mod.rs Wires up validator unit tests.
crates/libgraphql-core-v1/src/validators/tests/object_or_interface_type_validator_tests.rs Adds test coverage for object/interface implementation validation rules.
crates/libgraphql-core-v1/src/validators/tests/union_type_validator_tests.rs Adds test coverage for union member validation rules.
crates/libgraphql-core-v1/src/validators/tests/input_object_type_validator_tests.rs Adds test coverage for input object field validation and cycle detection.
crates/libgraphql-core-v1/src/validators/tests/directive_definition_validator_tests.rs Adds test coverage for directive definition parameter validation.
crates/libgraphql-core-v1/src/schema/type_validation_error.rs Updates error formatting for circular input field chains.
crates/libgraphql-core-v1/src/schema/tests/type_validation_error_tests.rs Adjusts tests to match updated error display formatting.
Comments suppressed due to low confidence (1)

crates/libgraphql-core-v1/src/schema/type_validation_error.rs:66

  • CircularInputFieldChain Display wraps each path element in backticks, but the validator currently builds circular_field_path elements that already include backticks (e.g. "A" / "A.b"). This will produce double backticks in real error messages (e.g. "A"). Prefer storing raw path segments (no backticks) in circular_field_path and only formatting in Display, or revert this Display change and keep formatting at the source consistently.
    #[error(
        "circular non-nullable input field chain: {}",
        circular_field_path.iter().map(|t| format!("`{t}`")).collect::<Vec<_>>().join(" -> "),
    )]
    CircularInputFieldChain {
        circular_field_path: Vec<String>,
    },

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/input_object_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/input_object_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/directive_definition_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/directive_definition_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/union_type_validator.rs Outdated
@jeffmo

jeffmo commented Apr 9, 2026

Copy link
Copy Markdown
Owner Author

Code review by graphql-rust-reviewer (Opus 1M) — 3 bugs, 4 test gaps, 1 spec gap, 1 nit:

Bugs (must fix):

  1. (moderate) input_object_type_validator.rs: Double backtick wrapping — validator wraps path items in backticks, then #[error] wraps again. Produces \`A.b``instead of`A.b``.
  2. (moderate) input_object_type_validator.rs:114-155: Path leaking — extend_from_slice pushes 2 items but only 1 pop() at line 155. Stale entries accumulate across field iterations, producing incorrect cycle paths.
  3. (moderate) input_object_type_validator.rs:161-173: [A!]! should break circular chains per spec. Current code only breaks on nullable lists. Spec says ANY list type breaks cycles (empty list is always constructible).

Spec gap:
4. (minor) object_or_interface_type_validator.rs: Missing IsValidImplementation step 2.f — deprecated field consistency check. May be intentionally deferred from v0.

Test gaps:
5. (minor) No test for self-referencing input object (A -> A cycle)
6. (minor) No test for three-node circular chain (A -> B -> C -> A)
7. (minor) No test for list-type cycle breaking ([A!]!)
8. (minor) No test with InterfaceType as the validated type (all tests use ObjectType)

Nit:
9. Directive validator reuses InvalidParameterWithOutputOnlyType awkwardly — both field_name and type_name set to directive display name, producing @auth.@auth(param).

…ng, directive param error, spec URLs, add tests
@jeffmo

jeffmo commented Apr 9, 2026

Copy link
Copy Markdown
Owner Author

All 9 items from the review addressed:

  1. Double backtick (bug) — removed backtick wrapping from validator; thiserror handles it
  2. Path leaking (bug) — added second pop() for the double extend_from_slice push
  3. List type cycle-breaking (spec) — renamed to annot_breaks_circular_chain, List arm unconditionally returns true per spec rule 3
  4. Deprecated field consistency (spec gap) — added TODO comment in validator + validation checklist item in plan
  5. Self-ref test — added circular_self_reference_detected
  6. Three-node test — added circular_three_node_chain_detected
  7. List-break test — added list_type_breaks_circular_chain
  8. InterfaceType test — added interface_implementing_interface_validates
  9. Directive param errortype_name set to empty string for cleaner message

Also fixed: all multi-line spec URLs consolidated to single lines, recursive child validator uses correct interface set.

174 tests pass.

@jeffmo jeffmo left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of Task 15: Validators.

Overall this is a solid implementation. The validators cover the key spec rules correctly, tests are well-structured with appropriate spec references, and the code is clean. I found 5 findings -- 1 bug, 2 test quality issues, and 2 style nits.

All tests pass, clippy is clean (with --tests), and spec references use the current September 2025 edition.

Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/directive_definition_validator.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/type_builders/tests/builder_validation_tests.rs Outdated
Comment thread crates/libgraphql-core-v1/src/schema/tests/schema_builder_tests.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/object_or_interface_type_validator.rs Outdated

@jeffmo jeffmo left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 6 code review -- final sanity pass. All tests pass, clippy is clean, imports are sorted, enum variants are alphabetically ordered, spec URLs are September 2025. Reviewed all 22 changed .rs files. Two low-severity observations below; no bugs or spec compliance gaps found.

Comment thread crates/libgraphql-core-v1/src/validators/directive_definition_validator.rs Outdated
@jeffmo jeffmo requested a review from Copilot April 12, 2026 05:25
…ameterType, edit-distance suggestions, find_similar_names everywhere

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/mod.rs
Comment thread libgraphql-core-v1-plan.md Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/union_type_validator.rs
Comment thread libgraphql-core-v1-plan.md Outdated
Comment thread libgraphql-core-v1-plan.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/libgraphql-core-v1/src/validators/edit_distance/mod.rs
Comment thread crates/libgraphql-core-v1/src/validators/edit_distance/mod.rs Outdated
Comment thread crates/libgraphql-core-v1/src/validators/edit_distance/tests.rs Outdated
@jeffmo jeffmo merged commit 3484cab into main Apr 12, 2026
12 checks passed
@jeffmo jeffmo deleted the lgcore_v1_task15 branch April 12, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants