Support spec_compliant_errors in Plug options#311
Open
donleandro wants to merge 1 commit intoabsinthe-graphql:mainfrom
Open
Support spec_compliant_errors in Plug options#311donleandro wants to merge 1 commit intoabsinthe-graphql:mainfrom
donleandro wants to merge 1 commit intoabsinthe-graphql:mainfrom
Conversation
Add spec_compliant_errors to @init_options, @raw_options, @TypeDoc, and @type so it flows through to the Absinthe pipeline. Also modify default_pipeline/2 to replace the bare Phase.Document.Result with {Phase.Document.Result, spec_compliant_errors: true} when the option is set, since Absinthe.Pipeline.for_document/2 does not pass options to the Result phase by default. Closes absinthe-graphql#284
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
This adds
spec_compliant_errorsas a supported option inAbsinthe.Plug, so users can opt into the modern GraphQL spec error format (extra error fields nested underextensionsinstead of at the top level).The option is added to
@init_options,@raw_options, the@typedoc, and the@type. It flows through the same path asanalyze_complexity,max_complexity, andtoken_limit.There's one extra piece needed beyond just forwarding the option:
Absinthe.Pipeline.for_document/2listsPhase.Document.Resultwithout options, so the option never reaches the Result phase on its own. To fix this,default_pipeline/2now replaces the bare phase with{Phase.Document.Result, spec_compliant_errors: true}when the option is set.Usage
Or at runtime:
Context
I ran into this while building Shiko, a veterinary platform. We wanted consistent error formatting across our GraphQL API, and the
spec_compliant_errorsoption in absinthe core was exactly what we needed - but it had no effect when configured through the Plug.Test plan
init/1places the option inraw_optionsextensionswhenspec_compliant_errors: trueCloses #284