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

Fix warnings for Decimal >= 1.6.0 #643

Merged
merged 1 commit into from
Nov 26, 2018

Conversation

samsondav
Copy link

Closes #642

@benwilson512 benwilson512 merged commit 22c4698 into absinthe-graphql:master Nov 26, 2018
@benwilson512
Copy link
Contributor

Thanks!

case Decimal.parse(value) do
{:ok, decimal} -> {:ok, decimal}
_ -> :error
end
end

def parse(%Absinthe.Blueprint.Input.Float{value: value}) do
decimal = Decimal.new(value)
def parse(%Absinthe.Blueprint.Input.Float{value: value}) when is_float(value) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add the is_float guard then we can remove the:

if Decimal.nan?(decimal), do: :error, else: {:ok, decimal}

line below, because for a float argument we're guaranteed to get a decimal that is not a nan. Same goes for an integer argument below. Was the intent before that value in Float{value: value} could have been a "NaN"?

I think this check makes sense for the clause above: String{value: value}) when is_binary(value).

Btw, in Ecto we're preventing NaN and +Inf/-Inf decimals as support for these varies between databases: https://github.com/elixir-ecto/ecto/blob/v3.0.3/lib/ecto/type.ex#L1198.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my reading of the spec NaN should be treated as null. I'll adjust accordingly.

def parse(%Absinthe.Blueprint.Input.Float{value: value}) do
decimal = Decimal.new(value)
def parse(%Absinthe.Blueprint.Input.Float{value: value}) when is_float(value) do
decimal = Decimal.from_float(value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this we need to bump decimal requirement from ~> 1.0 to at least ~> 1.5 as this function was only introduced in v1.5.0.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, what happened to this fix? We still get loads of warning for Decimal 1.6.0 when combined with newest Absinthe. Would be great to upgrade finally. Thanks.

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 this pull request may close these issues.

4 participants