Fail the compile when an epic or parent subquery does not compile

What does this MR do and why?

epic and parent resolve through a generated subquery whose compiled output becomes the variable's value. Nothing checked that the subquery compiled, so when it did not, its error text was stored as the value and the outer compile still reported success: true. parent = "abc" handed the API a WorkItemID! reading "id cannot be compared with ABC", and parent in ("", &1) and parent != ("") got past the empty-string guard from !537 (merged) the same way, because that guard matches only the bare scalar.

The structural fix, not the narrow one

Extending the Quoted("") guard to walk list items alone would have closed only the empty-string route and left every other unresolvable string (parent = "abc") silently broken. Instead, transform_epic_subquery_with_variable_type now returns Result<Value, GlqlError>, and the Result is carried all the way up so a subquery that cannot be built fails the compile outright:

  • SourceAnalyzer::graphql_filter_value now returns Result<Value, GlqlError> (trait change; all 12 implementors wrap in Ok, plus 4 test mocks)
  • GraphQLFilters::new returns Result<Self, GlqlError>
  • both codegen generate paths and generate_code return Result<CompileOutput, GlqlError>
  • lib.rs propagates with ? at the compile entry point

The List branch collects Result<Vec<_>, _>, so one bad item fails the whole list and no partial variable is pushed.

The user-facing error

The subquery's own error describes a query the author never wrote (parent = "abc" used to surface "id cannot be compared with ABC"), so the compiler reports in terms of what the author typed. Three kinds:

  • InvalidReference — the value does not parse as a reference (the iid it names is not a number). Covers parent = "abc", parent in ("abc", &1), epic = "x y", and an empty item in a list such as parent in ("", &1) or parent != (""): `parent` needs a work item or epic reference, such as `#12`, `my-group/my-project#12` or `&12`. `"abc"` does not name one. `epic` needs an epic reference, such as `&12` or `my-group&12`. `"abc"` does not name one.
  • EmptyReference (unchanged from main, scalar only) — parent = "", epic = "": `parent` needs a reference. An empty value names no object.
  • ReferenceSubqueryFailed — a well-formed reference whose subquery still does not compile; the subquery's own error is carried as the cause, so nothing is misattributed to the value. Example, a single-segment project path (which no real GitLab project has) leaves a bare reference no parent group to resolve in — project = "toplevel" and parent = #12: `parent` cannot resolve `#12`: `group` needs a path. An empty path names no group or project.

The empty-string guard in reject_empty_reference is unchanged from main: it still refuses the scalar spelling (parent = "") first, with its own message. Empty items inside a list (parent in ("", &1), parent != ("")) are not special-cased; they reach the subquery stage and are refused there by the structural check, as values with no iid in them. Fields such as label in ("", "bug") compile exactly as before.

How to set up and validate locally

cargo fmt -- --check
cargo clippy --all-targets -- -D warnings
cargo test

1913 tests pass, 0 failures. src/schema/schema.json is unchanged.

Tests: test_unresolvable_parent_reference_fails_the_compile and ..._epic_... pin InvalidReference for scalar and list spellings, including the empty list item; test_reference_subquery_failure_carries_its_own_cause pins ReferenceSubqueryFailed via the single-segment-project case for both parent and epic; test_unresolvable_parent_reference_fails_through_compile_entry_point drives the wasm compile entry with parent in (&1, "abc") and asserts variables == {}, so an error response cannot carry the variable the valid first item had already built (verified to fail against a deliberately leaking error path). The schema conformance sweep derives subquery-resolved fields from get_field_mapping and samples their String branches with the published reference example; two display-field tests that filtered on epic = "foo" incidentally now use epic = &1.

Reviewer notes

  • Two existing tests were passing because of the bug. test_response_with_epic and test_response_with_task_completion filtered on epic = "foo" incidentally while asserting display-field rendering. They now use epic = &1.
  • tests/schema_conformance.rs sampled every published String branch with "x". For a field that resolves its strings through a subquery (epic, parent) the published String kind is a reference written in quotes, so "x" now correctly fails. The sweep asks field_mapping::get_field_mapping which fields resolve that way — the one place that declares it — rather than keeping its own list. A future third subquery-resolved field would be picked up with no test change; today get_field_mapping has exactly two such arms, epic and parent.
  • ReferenceSubqueryFailed carries the subquery's error with its Error: prefix stripped, so the message reads as one sentence.

Closes #240 (closed)

Edited by Chandra Saripaka

Merge request reports

Loading
Loading