fix: prevent RuntimeError missing Absinthe.Phase.Document.Result for custom :result_phase (OPS-3643)#1
Open
palantir-valiot[bot] wants to merge 1 commit into
Conversation
….Result RuntimeError on jumps (OPS-3643) - Add native :result_phase support to Absinthe.Plug (passed via init/raw_options to default_pipeline which replaces and sets option for jumps). - Add defensive ensure_result_phase_consistent (called post document providers) so custom pipeline replaces of Result also work without mismatch on :result_phase in carried opts. - TDD: added failing-then-passing tests using custom pipeline override and direct option + complexity error path that triggers jump. - Bump to 1.4.6, update CHANGELOG. - Upgrade plug/poison (and transitives) within ranges + loosen plug constraint per keep-deps-fresh rule. Closes OPS-3643
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for a
:result_phaseoption toAbsinthe.Plug(and a post-pipeline normalization pass) so that replacingAbsinthe.Phase.Document.Result(either via the new option or a user:pipelineoverride) no longer producesRuntimeError: Could not find phase Elixir.Absinthe.Phase.Document.Resultwhen Absinthe phases jump to the result phase on validation/complexity/parse/etc. errors.The root cause was a mismatch:
for_document(and carried options on early phases) always targeted the defaultResult, while the pipeline list contained a replacement; jumps then didPipeline.from(remaining, Result)against a list that no longer contained it.result_phaseis now a first-class raw/init option, passed through, replaced indefault_pipeline/2, and the carried options updated.Absinthe.Plug.ensure_result_phase_consistent/1(invoked after document-provider pipeline munging) rewrites:result_phasein any carried opts to whatever *Result phase is actually present in the final list. This makes even naivedefault_pipeline(...) |> Pipeline.replace(Result, MyOrdered)patterns safe.Files changed: mix.exs, mix.lock, CHANGELOG.md, lib/absinthe/plug.ex:127 (raw_options + docs + default_pipeline + helpers), lib/absinthe/plug/request/query.ex:80 (the ensure call), test/lib/absinthe/plug_test.exs (TDD tests + CustomResult helper + pipeline fn).
Why
OPS-3643 (stitchex-lamosa-gto-prod prod crash, high severity code bug). The error was reported against valiot/absinthe_plug; the trigger was stitchex's
StitchexWeb.Plugs.GraphQL.pipeline/2(and similar patterns elsewhere) that doAbsinthe.Plug.default_pipeline(...) |> Absinthe.Pipeline.replace(Absinthe.Phase.Document.Result, OrderedResult)for field-order preservation. Same pattern is used by other consumers for Phoenix result structs etc. The fix belongs in the plug.See triage: NOTIFY+FIX for identifiable RuntimeError in first-party absinthe_plug.
Test plan
** (RuntimeError) Could not find phase Elixir.Absinthe.Phase.Document.Resultat plug.ex:run_query + pipeline.from (using @complex_query + max_complexity to force Complexity.Result jump).MIX_ENV=test elixir ... -S mix test test/lib/absinthe/plug_test.exs(with pa for test-only codec) → 30/30 green after fix (including original complexity, new custom-pipeline, and new direct-result_phasecases).mix format mix.exs lib/ test/mix hex.outdated+mix deps.update(plug/poison) + constraint bump in mix.exs; tests still green post-upgrade.git diffinspected (no debug, no scope creep, no empty hunks, only the described files).result_phase: MyModininit/1and post-default replace now result in the custom phase being present in the pipeline list and in all carried phase options.Closes OPS-3643