absinthe-graphql / absinthe

The GraphQL toolkit for Elixir
http://absinthe-graphql.org
Other
4.28k stars 524 forks source link

Strings containing only whitespace are being trimmed to an empty string #1300

Closed thenick775 closed 7 months ago

thenick775 commented 7 months ago

If submitting a bug, please provide the following:

Environment

Elixir 1.14.5 (compiled with Erlang/OTP 25)

* Absinthe version (mix deps | grep absinthe):

Expected behavior

Returning any string scalar field with only white space trimms the string to an empty string.

Ex. returning any of the following from a resolver: " " " " "\s"

Should return " " when fetching the query.

This is in alignment with the graphql string scalar spec, such that whitespace is significant: https://spec.graphql.org/October2021/#sec-String-Value

Actual behavior

Strings with only whitespace return as ""

Relevant Schema/Middleware Code

Note: I can try to provide an example, but take any sample phoenix app, add absinthe, and return a string from the resolver of the form shown above

benwilson512 commented 7 months ago

Hi @thenick775 can you please show a complete reproducible example? This example seems to indicate otherwise:

defmodule Bug do
  use Absinthe.Schema

  query do
    field :hello, :string do
      resolve fn _, _, _ ->
        {:ok, " "}
      end
    end
  end

end

Absinthe.run("{ hello }", Bug)
#=> {:ok, %{data: %{"hello" => " "}}}
thenick775 commented 7 months ago

Thank you, tracked this back down to ecto with empty_values through schemata, the last stop before we send to Absinthe.

My apologies for the confusion, and thank you for the example!

benwilson512 commented 7 months ago

Glad I could help!