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

Data is null when a number value is higher than i32 #980

Closed
seekeramento opened this issue Jul 13, 2022 · 9 comments
Closed

Data is null when a number value is higher than i32 #980

seekeramento opened this issue Jul 13, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@seekeramento
Copy link

seekeramento commented Jul 13, 2022

Expected Behavior

We should be able to use "SimpleObject" with a struct that has a field of the type i64

Actual Behavior

When the value of a field of the type i64 exceeds the limit of i32, queries always return null. This is even when we do not include this field in our selected fields

Steps to Reproduce the Problem

  1. Define a struct that uses the "#[derive(SimpleObject)]". This struct must have a field of the type i64.
  2. Define a gql query that has a return type of the simple struct you defined. Make it return an instance of this struct, and make sure to set a high i64 value. Please note that this bug does not appear when the value is low.
  3. Make GQL query that includes the i64 field.
  4. The returning data value is always null.

Specifications

  • Version:
    async-graphql = { version = "4.0.4", features = ["apollo_tracing"] }

  • Platform:
    Windows 11

@seekeramento seekeramento added the bug Something isn't working label Jul 13, 2022
@sunli829
Copy link
Collaborator

The GraphQL spec doesn't support int64, I recommend using StringNumber instead.

https://spec.graphql.org/October2021/#sec-Int

The Int scalar type represents a signed 32-bit numeric non-fractional value. Response formats that support a 32-bit integer or a number type should use that type to represent this scalar.

@seekeramento
Copy link
Author

I see. Does this mean that the field of my struct should be a "String"? Or there is another type to use as a part of this limitation?

@sunli829
Copy link
Collaborator

I recommend using string, StringNumber can help you.

#[derive(SimpleObject)]
struct Obj {
    int64_value: StringNumber<i64>,
}

@seekeramento
Copy link
Author

Thanks, will try it.

@seekeramento
Copy link
Author

How to import it?
use async_graphql::types::StringNumber;

or
use async_graphql::StringNumber;

Both did not work.

@seekeramento
Copy link
Author

Got it. Needed to add string_number to the features
async-graphql = { version = "4.0.4", features = ["apollo_tracing", "string_number"] }

@seekeramento
Copy link
Author

Cool StringNumber works fine, and it returns a string value. The only thing that I noticed that it does not implement the Default trait, which forces avoiding using the Default trait with the struct that uses it. Should we have a separate issue for this?

sunli829 added a commit that referenced this issue Jul 13, 2022
@sunli829
Copy link
Collaborator

Great idea, I've added it.

@seekeramento
Copy link
Author

As explained in the chain, StringNumber is what we need to handle numbers larger than i32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants