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

Confusing about the escaped chars in String of InputValue #510

Closed
UkonnRa opened this issue Jan 28, 2020 · 1 comment
Closed

Confusing about the escaped chars in String of InputValue #510

UkonnRa opened this issue Jan 28, 2020 · 1 comment

Comments

@UkonnRa
Copy link

UkonnRa commented Jan 28, 2020

Because now juniper does not support JSON scalar(#509), I have to pass a JSON Object using a piece of string, like:

let (res, errors) = juniper::execute_async(
      r#"mutation {
createUser(input: {
    nickname: "nickname",
    avatar: "http://example.com", 
    badges: "{\"Github\": \"https://github.com\"}"}) {
        id
        nickname
    }
}"#,
    None,
    &schema,
    &Variables::new(),
     &ctx,
).await.unwrap();

And then I created a new Scalar type named JsonValue:

juniper::graphql_scalar!(JsonValue where Scalar = <S> {
    // other definitions...
    from_input_value(v: &InputValue) -> Option<JsonValue> {
        v.as_string_value().and_then(|s| {
            println!("input string: {:?}", s);
            serde_json::from_str(s).ok()
        })
    }
}

What I want is receiving a string like: {"Github": "https://github.com"}, but in fact, I get:

{\"Github\": \"https://github.com\"}

I wonder if this a feature? How can I pass the string from input object correctly?

@LegNeato
Copy link
Member

You appear to be using Rust raw string literals (r#...#) which means you do not need to escape " on the Rust side. See https://rahul-thakoor.github.io/rust-raw-string-literals/.

Do you still see the resulting slashes if you remove them from the Rust side? If so please reopen!

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

No branches or pull requests

2 participants