From 98b243aa64e644df6e26d37e60c76da9fb732ad8 Mon Sep 17 00:00:00 2001 From: Sebastian Abondano Date: Mon, 5 Nov 2018 17:11:52 -0500 Subject: [PATCH] Fix no schema on GraphiQL Why: * For the schema to be available at `/graphiql` * Issue link: https://github.com/poanetwork/blockscout/issues/1042 This change addresses the need by: * Changing GraphQL `max_complexity` from 50 to 200 for introspection to be possible on GraphiQL. * Editing test that relied on a `max_complexity` of 50. --- apps/block_scout_web/lib/block_scout_web/router.ex | 7 +++++-- .../test/block_scout_web/schema/query/address_test.exs | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index dcf9717329..577a414163 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -38,10 +38,13 @@ defmodule BlockScoutWeb.Router do }) end + # Needs to be 200 to support the schema introspection for graphiql + @max_complexity 200 + forward("/graphql", Absinthe.Plug, schema: BlockScoutWeb.Schema, analyze_complexity: true, - max_complexity: 50 + max_complexity: @max_complexity ) forward("/graphiql", Absinthe.Plug.GraphiQL, @@ -49,7 +52,7 @@ defmodule BlockScoutWeb.Router do interface: :playground, socket: BlockScoutWeb.UserSocket, analyze_complexity: true, - max_complexity: 50 + max_complexity: @max_complexity ) scope "/", BlockScoutWeb do diff --git a/apps/block_scout_web/test/block_scout_web/schema/query/address_test.exs b/apps/block_scout_web/test/block_scout_web/schema/query/address_test.exs index 4854cf4738..f73c17e95e 100644 --- a/apps/block_scout_web/test/block_scout_web/schema/query/address_test.exs +++ b/apps/block_scout_web/test/block_scout_web/schema/query/address_test.exs @@ -114,10 +114,10 @@ defmodule BlockScoutWeb.Schema.Query.AddressTest do end test "correlates complexity to size of 'hashes' argument", %{conn: conn} do - # max of 12 addresses with four fields of complexity 1 can be fetched + # max of 50 addresses with four fields of complexity 1 can be fetched # per query: - # 12 * 4 = 48, which is less than a max complexity of 50 - hashes = 13 |> build_list(:address) |> Enum.map(&to_string(&1.hash)) + # 50 * 4 = 200, which is equal to a max complexity of 200 + hashes = 51 |> build_list(:address) |> Enum.map(&to_string(&1.hash)) query = """ query ($hashes: [AddressHash!]!) {