fix: fetching GraphQL schema by GraphiQL IDE (#9630)

pull/9804/head
Fedor Ivanov 8 months ago committed by GitHub
parent 25039ca731
commit 99a0e5668f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      apps/block_scout_web/config/config.exs
  2. 4
      apps/block_scout_web/test/block_scout_web/graphql/schema/query/address_test.exs
  3. 8
      apps/block_scout_web/test/block_scout_web/graphql/schema/query/addresses_test.exs
  4. 120
      apps/block_scout_web/test/block_scout_web/graphql/schema/query/introspection_test.exs
  5. 4
      config/runtime.exs

@ -97,8 +97,8 @@ config :block_scout_web, BlockScoutWeb.CSPHeader,
config :block_scout_web, Api.GraphQL, config :block_scout_web, Api.GraphQL,
enabled: ConfigHelper.parse_bool_env_var("API_GRAPHQL_ENABLED", "true"), enabled: ConfigHelper.parse_bool_env_var("API_GRAPHQL_ENABLED", "true"),
token_limit: ConfigHelper.parse_integer_env_var("API_GRAPHQL_TOKEN_LIMIT", 1000), token_limit: ConfigHelper.parse_integer_env_var("API_GRAPHQL_TOKEN_LIMIT", 1000),
# Needs to be 200 to support the schema introspection for graphiql # Needs to be 215 to support the schema introspection for graphiql
max_complexity: ConfigHelper.parse_integer_env_var("API_GRAPHQL_MAX_COMPLEXITY", 200) max_complexity: ConfigHelper.parse_integer_env_var("API_GRAPHQL_MAX_COMPLEXITY", 215)
# Configures Ueberauth local settings # Configures Ueberauth local settings
config :ueberauth, Ueberauth, config :ueberauth, Ueberauth,

@ -407,7 +407,9 @@ defmodule BlockScoutWeb.GraphQL.Schema.Query.AddressTest do
variables = %{ variables = %{
"hash" => to_string(address.hash), "hash" => to_string(address.hash),
"first" => 67 # Add +5 because of the increase in complexity limit. For more info, see
# https://github.com/blockscout/blockscout/pull/9630
"first" => 67 + 5
} }
conn = post(conn, "/api/v1/graphql", query: query, variables: variables) conn = post(conn, "/api/v1/graphql", query: query, variables: variables)

@ -157,10 +157,10 @@ defmodule BlockScoutWeb.GraphQL.Schema.Query.AddressesTest do
end end
test "correlates complexity to size of 'hashes' argument", %{conn: conn} do test "correlates complexity to size of 'hashes' argument", %{conn: conn} do
# max of 50 addresses with four fields of complexity 1 can be fetched # max of 53 addresses with four fields of complexity 1 can be fetched per
# per query: # query: 53 * 4 = 212, which is the upper bound before reaching the max
# 50 * 4 = 200, which is equal to a max complexity of 200 # complexity limit of 215
hashes = 51 |> build_list(:address) |> Enum.map(&to_string(&1.hash)) hashes = 54 |> build_list(:address) |> Enum.map(&to_string(&1.hash))
query = """ query = """
query ($hashes: [AddressHash!]!) { query ($hashes: [AddressHash!]!) {

@ -0,0 +1,120 @@
defmodule BlockScoutWeb.Schema.Query.IntrospectionTest do
use BlockScoutWeb.ConnCase
test "fetches schema", %{conn: conn} do
introspection_query = ~S"""
query IntrospectionQuery {
__schema {
queryType {
name
}
mutationType {
name
}
types {
...FullType
}
directives {
name
description
locations
args {
...InputValue
}
}
}
}
fragment FullType on __Type {
kind
name
description
fields(includeDeprecated: true) {
name
description
args {
...InputValue
}
type {
...TypeRef
}
isDeprecated
deprecationReason
}
inputFields {
...InputValue
}
interfaces {
...TypeRef
}
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
possibleTypes {
...TypeRef
}
}
fragment InputValue on __InputValue {
name
description
type {
...TypeRef
}
defaultValue
}
fragment TypeRef on __Type {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
ofType {
kind
name
}
}
}
}
}
}
}
}
}
}
"""
conn = get(conn, "/api/v1/graphql", query: introspection_query)
response = json_response(conn, 200)
assert %{"data" => %{"__schema" => %{"directives" => _}}} = response
end
end

@ -115,8 +115,8 @@ config :block_scout_web, Api.GraphQL,
), ),
enabled: ConfigHelper.parse_bool_env_var("API_GRAPHQL_ENABLED", "true"), enabled: ConfigHelper.parse_bool_env_var("API_GRAPHQL_ENABLED", "true"),
token_limit: ConfigHelper.parse_integer_env_var("API_GRAPHQL_TOKEN_LIMIT", 1000), token_limit: ConfigHelper.parse_integer_env_var("API_GRAPHQL_TOKEN_LIMIT", 1000),
# Needs to be 200 to support the schema introspection for graphiql # Needs to be 215 to support the schema introspection for graphiql
max_complexity: ConfigHelper.parse_integer_env_var("API_GRAPHQL_MAX_COMPLEXITY", 200) max_complexity: ConfigHelper.parse_integer_env_var("API_GRAPHQL_MAX_COMPLEXITY", 215)
# Configures History # Configures History
price_chart_config = price_chart_config =

Loading…
Cancel
Save