Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/absinthe/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,15 @@ defmodule Absinthe.Plug do
:pubsub,
:analyze_complexity,
:max_complexity,
:maximum_number_of_suggestions,
:token_limit,
:transport_batch_payload_key,
:standard_sse
]
@raw_options [
:analyze_complexity,
:max_complexity,
:maximum_number_of_suggestions,
:token_limit
]

Expand All @@ -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`)
Expand All @@ -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(),
Expand Down
27 changes: 27 additions & 0 deletions test/lib/absinthe/plug/transport_batching_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down