graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

[juniper_rocket] Document GET request syntax #1098

Closed ysulyma closed 1 year ago

ysulyma commented 2 years ago

I am using the Juniper Rocket example. The POST endpoint and GraphiQL interface work for me, but I can't figure out how to send a GET request. (I'm also new to using Rocket.) I have tried

/graphql?{}
/graphql?request={}
/graphql?query={}

where {} is a URL-encoded version of

{
  __schema {
    types {
      name
    }
  }
}

and none of these work for me.

An explicit example of a GET request that works would be helpful.

ilslv commented 2 years ago

@ysulyma /graphql?query should work, but rocket example is incorrect, as it uses Deserialize impl of GraphQLRequest. We'll address this in 0.16 release.

Until then you have 2 options:

  1. Use POST for both mutations and queries. This should be ok.
  2. Implement custom structure with right Deserialize impl and convert this struct into a GraphQLRequest.
tyranron commented 1 year ago

@ysulyma /graphql?query should work, but rocket example is incorrect, as it uses Deserialize impl of GraphQLRequest.

This is not true. In the specified example is used juniper_rocket::GraphQLRequest, rather than juniper::http::GraphQLRequest, and it doesn't implement Deserialize at all. In fact, it implements FromForm, which gives it ability to being parsed from URL query strings. So all this works okay. Passing juniper::http::tests confirms it.

The example, however, is really broken. Rather than having

#[rocket::get("/graphql?<request>")]

attribute, it should have

#[rocket::get("/graphql?<request..>")]
tyranron commented 1 year ago

@ysulyma the example was fixed, and now mentions the GET request query format: https://github.com/graphql-rust/juniper/blob/bd8dc582a418f80d40a1b0ca969d3a6d4d77e2a6/juniper_rocket/examples/simple.rs#L29-L41