apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.87k stars 717 forks source link

GraphQLNullable<Decimal> conversion #3305

Closed satyaaiosdev closed 8 months ago

satyaaiosdev commented 9 months ago

Question

The conversion of Decimal to GraphQLNullable resulted in odd behavior, such as the addition of extra numbers to the value as shown below. Take GraphQLNullable, for instance.A portion (0.84) receives 0.83999999999999997 However, after conversion, 0.84 was our need.How can one resolve this kind of problem?

AnthonyMDev commented 9 months ago

Can you provide a code sample of what you are doing when this conversion occurs? That is definitely very odd behavior...

satyaaiosdev commented 9 months ago

let decimal: Decimal = 0.84 let unwrapDecimal = GraphQLNullable.some(0.84) this is getting 0.83999999999999997 and this value send to backend

satyaaiosdev commented 9 months ago

@AnthonyMDev waiting for your response, FloatingType values are wrongly presiced.

AnthonyMDev commented 9 months ago

Hi there. Sorry for the slow response, we've been off for the holidays. Now that we are back, we've got a lot of catch up to do this week. But we'll get someone to look into this further as soon as we can. If you end up finding anything else out in the mean time, please update us here!

satyaaiosdev commented 9 months ago

Hi @AnthonyMDev , not only GraphQLNullable, while sending Decimal(decimal: 0.83) is converted into 8.0299999999999994

BobaFetters commented 8 months ago

@satyaaiosdev Can you provide a sample project that demonstrates this issue? In my testing using Decimal and passing it into GraphQLNullable as described doesn't demonstrate the issue so I assume the issue is coming from somewhere this variable is being used or acted upon in some way in your code. A sample project that demonstrates the issue would be helpful for us to determine the cause of the issue.

satyaaiosdev commented 8 months ago

MocupInput(__data: ApolloAPI.InputDict(data: [ "currentBalance": GraphQL.Decimal(decimal:0.83)]))

Than while sending this input request query creating like this requestBody ----- { "operationName" : "MocupAggtegate", "query" : "query MocupAggtegate($input: MocupAggregateInput!) {\n mocupAggregate(input: $input) {\n __typename\n totalValue\n }\n}", "variables" : { "input" : { "totalValue" : 8.0299999999999994, } }

BobaFetters commented 8 months ago

@satyaaiosdev sorry for the delayed response ive been out of office dealing with a death in the family.

so you are using GraphQL.Decimal which I assume is a custom scalar you have implemented? Can you share your implementation of that?

BobaFetters commented 8 months ago

Closing this under the assumption it is no longer an issue. Feel free to reopen with additional info if needed.

github-actions[bot] commented 8 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.