juniper
juniper copied to clipboard
[juniper_rocket] Document GET request syntax
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.
@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:
- Use
POSTfor both mutations and queries. This should be ok. - Implement custom structure with right
Deserializeimpl and convert this struct into aGraphQLRequest.
@ysulyma
/graphql?queryshould work, butrocketexample is incorrect, as it usesDeserializeimpl ofGraphQLRequest.
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..>")]
@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