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

Support decoding Decimal as String #490

Conversation

jessey2024
Copy link

Allows converting Decimal to String when decoding.
Currently, an error is being thrown.

@apollo-cla
Copy link

@jessey2024: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

Copy link

netlify bot commented Sep 24, 2024

👷 Deploy request for eclectic-pie-88a2ba pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3bd847b

Copy link

netlify bot commented Sep 24, 2024

👷 Deploy request for apollo-ios-docc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3bd847b

@calvincestari
Copy link
Member

Hi @jessey2024, can you give me some more context on how this is needed or where it's useful - thanks.

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

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

Hi @jessey2024, thanks so much for the PR! This doesn't seem to be likely to cause any issues, but I'm unclear of when you would need this? This function is used for converting a JSON value into a String. Using JSONSerialization, wouldn't any decimal number be serialized as a Double? In what situation is this code actually being called?

@AnthonyMDev
Copy link
Contributor

Ha, I didn't see @calvincestari's response before replying here. :)

@jessey2024
Copy link
Author

jessey2024 commented Sep 24, 2024

Hi @jessey2024, can you give me some more context on how this is needed or where it's useful - thanks.

Hi @calvincestari and @AnthonyMDev,
We currently have values of different number types returning from the API.
In our project, these values are defined as a common type which is aliased to Swift.String.
This works fine (with integers and floats) until we receive a Decimal value, and the decoding error is thrown.

@calvincestari
Copy link
Member

OK, that makes more sense. I suggest reading our documentation about Custom Scalars as that would be the correct way to deal with types outside of the standard GraphQL scalars.

@calvincestari
Copy link
Member

calvincestari commented Sep 24, 2024

@jessey2024 - I'm going to close this PR as I believe Custom Scalars is the correct way to do what you need with those types. If you try that and still have errors then comment in this issue again and we can take another look.

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