absinthe icon indicating copy to clipboard operation
absinthe copied to clipboard

Dialyzer error when expecting "subscribed" key returned from Absinthe.run/3

Open twinn opened this issue 1 year ago • 0 comments

Environment

  • Elixir version (elixir -v): 1.14.1
  • Absinthe version (mix deps | grep absinthe): 1.7.0
  • Client Framework and version (Relay, Apollo, etc): n/a

Expected behavior

mix dializer to recognize "subscribed" as a valid return key for Absinthe.run/3

Actual behavior

lib/subscription.ex:69:pattern_match
The pattern can never match the type.

Pattern:
{:ok, %{<<115, 117, 98, 115, 99, 114, 105, 98, 101, 100>> => _topic}}

Type:

  {:error, binary()}
  | {:ok,
     %{
       :data => nil | %{binary() => atom() | binary() | [map()] | number() | map()},
       :errors => [
         %{
           :message => binary(),
           :locations => [%{:column => integer(), :line => pos_integer()}]
         }
       ]
     }}

This is the Absinthe.run_result() type which doesn't expect to return a "subscribed" key as described in the Understanding Subscriptions Guide.

Relevant Schema/Middleware Code

  @spec run(t()) :: {:ok, String.t()}
  def run(%__MODULE__{
        runner_args: %{schema: schema, query: query, context: context, variables: variables}
      }) do
    {:ok, %{"subscribed" => topic}} = Absinthe.run(query, schema,
      context: context,
      variables: variables
    )
    {:ok, topic}
  end

twinn avatar Mar 16 '23 13:03 twinn