Skip to content

downloadsRemaining returns null when is valid type string #937

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

Open
hacknug opened this issue May 23, 2025 · 0 comments · May be fixed by #938
Open

downloadsRemaining returns null when is valid type string #937

hacknug opened this issue May 23, 2025 · 0 comments · May be fixed by #938

Comments

@hacknug
Copy link

hacknug commented May 23, 2025

Describe the bug
For some reason, downloadsRemaining is not always of type integer and sometimes is a numeric string.

To Reproduce
Not 100% how to reproduce since this doesn't seem to be mentioned in other issues and I'm not sure if it's a generalized issue of a feature no one uses or something more specific to my setup.

In my case I changed the downloadsRemaining field using the order ui after purchase. GraphiQL kept showing null as the value which invited me to look into this.

Maybe this change post-sale is what causes the type to be of type string instead of the expected integer.

Expected behavior
The plugin should handle the different possible types of the property to ensure it doesn't return null when it's a valid value of type string.

Screenshots
If applicable, add screenshots to help explain your problem.

Plugin Versions

  • WooGraphQL Version: 0.21.0
  • WPGraphQL Version: 1.28.1
  • WPGraphQL CORS Version: 2.1
  • WordPress Version: 6.8.1
  • WooCommerce Version: 9.1.2

I'm not currently using the latest versions for all plugins for compatibility reasons with another plugin (will update at a later date once development of the project is done).

Additional context
Opening a PR with the fix. It mirrors the approach used in WooCommerce's templates where they use is_numeric() to check for a valid value:

https://github.com/woocommerce/woocommerce/blob/e5cc0747d0cd997a947c0df6822925c9842d269a/plugins/woocommerce/templates/myaccount/my-downloads.php#L37

I then parse it as an integer using intval().

The fix doesn't change the intended behavior of the plugin, it only ensures a correct parsing of valid values in order to not nullify them on the API.

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.

1 participant