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

Using variables produces invalid value errors #390

Closed
jatsrt opened this issue Jul 10, 2019 · 9 comments
Closed

Using variables produces invalid value errors #390

jatsrt opened this issue Jul 10, 2019 · 9 comments
Labels
bug Something isn't working needs-triage

Comments

@jatsrt
Copy link

jatsrt commented Jul 10, 2019

Describe the bug
When using "variables" to sent a nested/complex object, the request fails with "got invalid value"

To Reproduce

mutation {
  update(update: {where: {id: "xxxxxxxxxx"}, data: {bedrooms: 1, location: {lat: 41.2 lon: -87.6}}}) {
    id
  }
}

vs

mutation Update($update: Update!) {
  update(update: $update) {
    id
  }
}

{"update": {
  "where": {
    "id": "xxxxxxxxxx"
  },
  "data": {
   "bedrooms": 1, "location": {"lat": 41.2, "lon": -87.6}
  }
}
}

Produces the errors like:

{
      "message": "Variable \"$update\" got invalid value. In field \"data\": In field \"bedrooms\": Expected \"Int\".",
      "locations": [
        {
          "line": 1,
          "column": 17
        }
      ]
    }

Expected behavior
Should work/parse the same as the first example.

@jatsrt jatsrt added bug Something isn't working needs-triage labels Jul 10, 2019
@jatsrt jatsrt changed the title Invalid Values Using variables produces invalid value errors Jul 10, 2019
@LegNeato
Copy link
Member

Interesting. To clarify, Update is an InputObject consisting of the content from the first example (which works)?

@jatsrt
Copy link
Author

jatsrt commented Jul 11, 2019

Correct, the following also does not work. Also, strings and IDs seem ok, just tripping up on Ints and Floats, I have not tried all scalar types, or custom scalars.

mutation Update($data: UpdateData!) {
  update(update: {where: {id: "xxxxxxxx"}, data: $data}) {
    id
  }
}

{ "data": {
   "bedrooms": 1, "location": {"lat": 41.2, "lon": -87.6}
  }
}

@jatsrt
Copy link
Author

jatsrt commented Jul 11, 2019

More testing, enums work, chrono date time works. Right now just Int and Float seem to be the issue

@jatsrt
Copy link
Author

jatsrt commented Jul 11, 2019

Running it as a test using the following works too. Status and propertyType are enums, bedrooms is i32/Int

&vec![
                (
                    "where".to_owned(),
                    InputValue::object(vec![("id", InputValue::scalar("xxxxxxxxx"))].into_iter().collect()),
                ),
                (
                    "data".to_owned(),
                    InputValue::object(
                        vec![
                            ("status", InputValue::scalar("OTHER")),
                            ("propertyType", InputValue::scalar("OTHER")),
                            ("bedrooms", InputValue::scalar(1)),
                        ]
                        .into_iter()
                        .collect(),
                    ),
                ),
            ]
            .into_iter()
            .collect(),

@jatsrt
Copy link
Author

jatsrt commented Jul 11, 2019

OK, root cause identified, not sure if it is something juniper should handle or not though.
One of my deep dependencies sets serde_json = { version = "1.0", features = ["arbitrary_precision"] }

This changes the behavior globally and causes the input validation for numbers only to fail.

@LegNeato
Copy link
Member

Ugh, that is annoying! Looks like this could be serde-rs/json#505 ?

@LegNeato
Copy link
Member

What server integration are you using this with? I might try the workaround in that bug.

@jatsrt
Copy link
Author

jatsrt commented Jul 16, 2019

Warp, the serde_json config was due to an internal library that was a dependency of a dependency.

@saskenuba
Copy link

I'm having the same issue. My queries accepting i32 on parameters always return errors such as:
"message": "Variable \"$assetsToDeposit\" got invalid value. In element #0: In field \"appid\": Expected \"Int\".".

And this doesn't matter if it is an input object or a raw scalar, neither works. But if I parse them from a String, it works normally.

Query:

query DepositRequest($assetsToDeposit: [AssetNewTradeOffer!]!) {
  depositRequest(assetsToDeposit: $assetsToDeposit)
}

Variables:

{
	"assetsToDeposit": [
		{
			"appid": 730,
			"contextid": 2,
			"assetid": ["17099917172"],
			"price": "100"
		}
	]
}

Response:

{
  "errors": [
    {
      "message": "Variable \"$assetsToDeposit\" got invalid value. In element #0: In field \"appid\": Expected \"Int\".",
      "locations": [
        {
          "line": 1,
          "column": 22
        }
      ]
    },
    {
      "message": "Variable \"$assetsToDeposit\" got invalid value. In element #0: In field \"contextid\": Expected \"Int\".",
      "locations": [
        {
          "line": 1,
          "column": 22
        }
      ]
    }
  ]
}
#[derive(GraphQLInputObject, Clone, Debug)]
pub struct AssetNewTradeOffer {
    appid: i32,
    contextid: i32,
    assetid: Vec<Long>,
    price: Long,
}

async fn deposit_request(context: &Context, assets_to_deposit: Vec<AssetNewTradeOffer>) -> FieldResult<i32> { ... }

After using cargo tree -e features -i serde_json, I found that a dependency is using the arbitrary_precision feature of serde_json as @jatsrt described, but I still haven't disabled it to check if it affects behaviour.

I am not sure if this dep introduced this bug because until now, there were no queries with i32 only strings.

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

No branches or pull requests

3 participants