juniper icon indicating copy to clipboard operation
juniper copied to clipboard

[juniper_rocket] Document GET request syntax

Open ysulyma opened this issue 2 years ago • 1 comments

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 avatar Aug 26 '22 23:08 ysulyma

@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.

ilslv avatar Aug 29 '22 06:08 ilslv

@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 avatar Nov 24 '23 15:11 tyranron

@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

tyranron avatar Nov 24 '23 17:11 tyranron