diff --git a/lib/absinthe/plug.ex b/lib/absinthe/plug.ex index f5a6a45..a78d4c4 100644 --- a/lib/absinthe/plug.ex +++ b/lib/absinthe/plug.ex @@ -139,6 +139,7 @@ defmodule Absinthe.Plug do :pubsub, :analyze_complexity, :max_complexity, + :maximum_number_of_suggestions, :token_limit, :transport_batch_payload_key, :standard_sse @@ -146,6 +147,7 @@ defmodule Absinthe.Plug do @raw_options [ :analyze_complexity, :max_complexity, + :maximum_number_of_suggestions, :token_limit ] @@ -166,6 +168,8 @@ defmodule Absinthe.Plug do - `:pubsub` -- (Optional) Pub Sub module for Subscriptions. - `:analyze_complexity` -- (Optional) Set whether to calculate the complexity of incoming GraphQL queries. - `:max_complexity` -- (Optional) Set the maximum allowed complexity of the GraphQL query. If a document’s calculated complexity exceeds the maximum, resolution will be skipped and an error will be returned in the result detailing the calculated and maximum complexities. + - `:maximum_number_of_suggestions` -- (Optional) An integer for the maximum number of suggestions + to be used on error messages. 0 can be passed to disable suggestions and avoid schema instrospection. - `:token_limit` -- (Optional) Set a limit on the number of allowed parseable tokens in the GraphQL query. Queries with exceedingly high token counts can be expensive to parse. If a query's token count exceeds the set limit, an error will be returned during Absinthe parsing (default: `:infinity`). - `:transport_batch_payload_key` -- (Optional) Set whether or not to nest Transport Batch request results in a `payload` key. Older clients expected this key to be present, but newer clients have dropped this pattern. (default: `true`) - `:standard_sse` -- (Optional) Set whether or not to adopt SSE standard. Older clients don't support this key. (default: `false`) @@ -184,6 +188,7 @@ defmodule Absinthe.Plug do | {module, atom}, analyze_complexity: boolean, max_complexity: non_neg_integer | :infinity, + maximum_number_of_suggestions: non_neg_integer | nil, token_limit: non_neg_integer | :infinity, serializer: module | {module, Keyword.t()}, content_type: String.t(), diff --git a/test/lib/absinthe/plug/transport_batching_test.exs b/test/lib/absinthe/plug/transport_batching_test.exs index 5f27fdf..cbbe2c8 100644 --- a/test/lib/absinthe/plug/transport_batching_test.exs +++ b/test/lib/absinthe/plug/transport_batching_test.exs @@ -240,6 +240,33 @@ defmodule Absinthe.Plug.TransportBatchingTest do assert @fragment_query_with_undefined_variable_result == resp_body end + + test "can disable suggestions on error" do + opts = Absinthe.Plug.init(schema: TestSchema, maximum_number_of_suggestions: 0) + + assert %{status: 200, resp_body: resp_body} = + :post + |> conn("/", @fragment_query_with_undefined_field) + |> put_req_header("content-type", "application/json") + |> plug_parser() + |> absinthe_plug(opts) + + assert [ + %{"id" => "1", "payload" => %{"data" => %{"item" => %{"name" => "Foo"}}}}, + %{ + "id" => "2", + "payload" => %{ + "errors" => [ + %{ + "message" => "Cannot query field \"namep\" on type \"Item\".", + "locations" => [%{"line" => 1, "column" => 67}] + } + ] + } + } + ] == resp_body + end + test "it can use resolution batching across documents" do {:ok, pid} = Counter.start_link(0) opts = Absinthe.Plug.init(schema: TestSchema, context: %{counter: pid})