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

bug: Graphql doesn't work Body should be a JSON object #401

Closed
marc2332 opened this issue Jul 6, 2023 · 4 comments
Closed

bug: Graphql doesn't work Body should be a JSON object #401

marc2332 opened this issue Jul 6, 2023 · 4 comments

Comments

@marc2332
Copy link
Contributor

marc2332 commented Jul 6, 2023

Hi, I am trying to make a graphql request but even the example snippet fails:

Code:

use octocrab::Octocrab;

#[tokio::main]
async fn main() {
    let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required");

    let gh = Octocrab::builder().personal_token(token).build().unwrap();

    let response = gh
        .graphql::<serde_json::Value>("{ 'query': '{ viewer { login }}' }")
        .await;

    println!("{:?}", response);
}

Error:

GitHub { source: GitHubError { documentation_url: Some("https://docs.github.com/graphql"), errors: None, message: "Body should be a JSON object" },
@XAMPPRocky
Copy link
Owner

XAMPPRocky commented Jul 8, 2023

Thank you for your issue! The error is self-evident, you're passing a string and not a JSON object.

let response = gh.graphql(serde_json::json!({ "query": "{ viewer { login }}" })).await;

@marc2332
Copy link
Contributor Author

marc2332 commented Jul 8, 2023

let response = gh.graphql(serde_json::json!({ "query": "{ viewer { login }}" })).await;

Ah nice, I suggest you update the example code from

/// .graphql("{ 'query': '{ viewer { login }}' }")
so others don't have the same error as I did 👍

Thank you 😄

@XAMPPRocky
Copy link
Owner

Ah nice, I suggest you update the example code from

Thanks for the catch, I don't have the time right now, but if you wanted to make a quick Pr, I'd be happy to accept it 🙂

@marc2332
Copy link
Contributor Author

marc2332 commented Jul 8, 2023

Ah nice, I suggest you update the example code from

Thanks for the catch, I don't have the time right now, but if you wanted to make a quick Pr, I'd be happy to accept it 🙂

Ohh, no worries! I will make the PR asap 😄 👍

Nice library btw, I like it!

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