Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blueprint inside telemetry events comes out as Inspect.Error when in IEx #1185

Open
MikaAK opened this issue Aug 12, 2022 · 4 comments
Open

Comments

@MikaAK
Copy link
Contributor

MikaAK commented Aug 12, 2022

Environment

  • Elixir version (elixir -v): 1.13.3
  • Absinthe version (mix deps | grep absinthe): 1.7
  • Client Framework and version (Relay, Apollo, etc): GraphiQL Interface

Expected behavior

We get the blueprint struct instead of an Inspect.Error

Actual behavior

Inspect.Error on the blueprint field in the [:execute, :operation, :stop] event when using fragments or subscriptions

Relevant Schema/Middleware Code

In an iex shell when printing it out you get

%Inspect.Error{
    message: "got MatchError with message \"no match of right hand side value: %Absinthe.Blueprint{adapter: Absinthe.Adapter.LanguageConventions, directives: [], errors: [], execution: %Absinthe.Blueprint.Execution{...}...
  },
@MikaAK MikaAK changed the title blueprint inside telemetry events comes out as Inspect.Error when using subscriptions or fragments blueprint inside telemetry events comes out as Inspect.Error when in IEx Aug 12, 2022
@maartenvanvliet
Copy link
Contributor

I could not reproduce this. Do you have a step by step guide on getting this error?

@kdawgwilk
Copy link
Contributor

This is likely related to another bug but we will need to see a more concrete schema example that reproduces this to narrow it down a bit more

@MikaAK
Copy link
Contributor Author

MikaAK commented Aug 30, 2022

I can send a example schema since it happens on any request in our app, just OOO this week but I'll be back in Monday

@aseigo
Copy link

aseigo commented Nov 28, 2023

Using Elixir 1.15.7 (compiled with Erlang/OTP 26), various errors occur with any schema. For instance, this simple toy schema:

defmodule FSGraphQL.GraphQL.Schema do
  use Absinthe.Schema
  @schema_provider Absinthe.Schema.PersistentTerm
  import_types(Absinthe.Type.Custom)

  def list_features(_, _, _), do: {:ok, []}

  @desc "Metric source types"
  enum :source_type do
    value(:space_area, as: :spacearea, description: "Area")
    value(:metric, as: "Metric", description: "Calculated metric")
  end

  object :branches do
    field :global_id, :string
    field :description, :string
    field :source, :source_type
  end

  input_object :global_id_filter do
    field :global_id, :string
  end

  query do
    field :all_branches, list_of(:branches) do
      arg(:filter, :global_id_filter)
      resolve(&list_features/3)
    end
  end
end

Then inspecting FSGraphQL.GraphQL.Schema.__absinthe_blueprint__ with or without pretty: false results in:

#Inspect.Error<
  got RuntimeError with message:

      """
      Unexpected nil
      """

  while inspecting:
[... schema struct ...]

  Stacktrace:

    (absinthe 1.7.6) lib/absinthe/schema/notation/sdl_render.ex:246: Absinthe.Schema.Notation.SDL.Render.render/2
    (elixir 1.15.7) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (absinthe 1.7.6) lib/absinthe/schema/notation/sdl_render.ex:51: Absinthe.Schema.Notation.SDL.Render.render/2
    (absinthe 1.7.6) lib/absinthe/schema/notation/sdl_render.ex:12: Absinthe.Schema.Notation.SDL.Render.inspect/2
    (elixir 1.15.7) lib/inspect/algebra.ex:348: Inspect.Algebra.to_doc/2
    (elixir 1.15.7) lib/kernel.ex:2366: Kernel.inspect/2
    (iex 1.15.7) lib/iex/evaluator.ex:375: IEx.Evaluator.io_inspect/1
    (iex 1.15.7) lib/iex/evaluator.ex:334: IEx.Evaluator.eval_and_inspect/3
    (iex 1.15.7) lib/iex/evaluator.ex:305: IEx.Evaluator.eval_and_inspect_parsed/3
    (iex 1.15.7) lib/iex/evaluator.ex:294: IEx.Evaluator.parse_eval_inspect/4
    (iex 1.15.7) lib/iex/evaluator.ex:187: IEx.Evaluator.loop/1
    (iex 1.15.7) lib/iex/evaluator.ex:32: IEx.Evaluator.init/5
    (stdlib 5.1.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

Making a Blueprint "by hand" does not render either:

%Absinthe.Blueprint{}

%Absinthe.Blueprint{name: "My Model", schema: FSGraphQL.GraphQL.Schema, schema_definitions: [%Absinthe.Blueprint.Schema.SchemaDefinition{schema_declaration: "MyModel"}]} 

%Absinthe.Blueprint{name: "Urban Model", schema: FSGraphQL.GraphQL.Schema, schema_definitions: [%Absinthe.Blueprint.Schema.SchemaDefinition{schema_declaration: "UrbanModel"}]}

These kick up various errors, including:

#Inspect.Error<
  got MatchError with message:

      """
      no match of right hand side value: %Absinthe.Blueprint{operations: [], directives: [], fragments: [], name: nil, schema_definitions: [], schema: nil, prototype_schema: nil, adapter: nil, initial_phases: [], telemetry: %{}, flags: %{}, errors: [], input: nil, source: nil, execution: %Absinthe.Blueprint.Execution{adapter: nil, schema: nil, fragments: %{}, fields_cache: %{}, validation_errors: [], result: nil, acc: %{}, context: %{}, root_value: %{}}, result: %{}}
      """
>

#Inspect.Error<
  got FunctionClauseError with message:

      """
      no function clause matching in Absinthe.Schema.Notation.SDL.Render.render/2
      """
>

I'm not sure what the expectations are for completeness / setup of these structs, but the renderer seems to fail with default constructions, bare bones manual constructions, and schemas generated from modules. This is true whether or not pretty: true is passed to IO.inspect.

The only reliable way I can see any useful output is to run the struct through Map.from_struct first to bypass the inspect code in Absinthe itself. Annoyingly, doing this on the __asinthe_blueprint__ from a schema module only helps with the top-level Blueprint struct, and the intereior Schema.SchemaDefinition struct will against error out in e.g. SchemaDefition.type_definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants