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

"Cannot return null for non-nullable field" present when error was specified #803

Closed
virtual-light opened this issue Nov 11, 2019 · 2 comments · Fixed by #816
Closed

"Cannot return null for non-nullable field" present when error was specified #803

virtual-light opened this issue Nov 11, 2019 · 2 comments · Fixed by #816

Comments

@virtual-light
Copy link

Environment

Elixir 1.9.0 (compiled with Erlang/OTP 22)
absinthe 1.4.16 (Hex package) (mix)
absinthe_relay 1.4.6 (Hex package) (mix)
absinthe_plug 1.4.7 (Hex package) (mix)

Expected behavior

According to current GQL specification paragraph 6.4.4 and working draft of new GQL specification paragraph 6.4.4.

If the field returns null because of an error which has already been added to the "errors" list in the response, the "errors" list must not be further affected. That is, only one error should be added to the errors list per field.

That means, that when non_null field has nil value, but there is already an error related to that field, then "Cannot return null for non-nullable field" error should not be propagated.

For example, if query

field :user, non_null(:user) do
  arg :id, non_null(:id)
  resolve fn args, resolution -> 
   case authorize(args, resolution.context.current_user) do
    :ok
      # next steps
      {:ok, user}
    :error
      {:error, :unauthorized}
  end  
end

returns {:error, :unauthorized} then errors list should contain only one error in response:

%{
  "data" => nil,
  "errors" => [
    %{
      "locations" => [%{"column" => 0, "line" => 2}],
      "message" => "unauthorized",
      "path" => ["user"]
    }
  ]
}

Actual behavior

"Cannot return null for non-nullable field" present in errors list in response.

%{
  "data" => nil,
  "errors" => [
    %{
      "locations" => [%{"column" => 0, "line" => 2}],
      "message" => "Cannot return null for non-nullable field",
      "path" => ["user"]
    },
    %{
      "locations" => [%{"column" => 0, "line" => 2}],
      "message" => "unauthorized",
      "path" => ["user"]
    }
}
@virtual-light virtual-light changed the title `"Cannot return null for non-nullable field" present when error was specified "Cannot return null for non-nullable field" present when error was specified Nov 11, 2019
@benwilson512
Copy link
Contributor

Ah, it seems they changed the wording on this. Will fix.

@binaryseed
Copy link
Contributor

I put together a small PR to tackle this #816

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

Successfully merging a pull request may close this issue.

3 participants