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

[juniper_rocket] Document GET request syntax #1098

Closed
ysulyma opened this issue Aug 26, 2022 · 3 comments · Fixed by #1223
Closed

[juniper_rocket] Document GET request syntax #1098

ysulyma opened this issue Aug 26, 2022 · 3 comments · Fixed by #1223
Assignees
Labels
bug Something isn't working enhancement Improvement of existing features or bugfix k::documentation Related to project documentation k::example Related to usage examples k::integration Related to integration with third-party libraries or systems lib::rocket Related to `rocket` crate integration
Milestone

Comments

@ysulyma
Copy link

ysulyma commented Aug 26, 2022

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
Copy link
Member

ilslv commented Aug 29, 2022

@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 ilslv added the bug Something isn't working label Aug 29, 2022
@ilslv ilslv added this to the 0.16.0 milestone Aug 29, 2022
@ilslv ilslv self-assigned this Aug 29, 2022
@tyranron tyranron added the k::integration Related to integration with third-party libraries or systems label Aug 29, 2022
@tyranron tyranron assigned tyranron and unassigned ilslv Nov 24, 2023
@tyranron
Copy link
Member

@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 tyranron added k::example Related to usage examples enhancement Improvement of existing features or bugfix k::documentation Related to project documentation and removed k::integration Related to integration with third-party libraries or systems labels Nov 24, 2023
@tyranron tyranron added lib::rocket Related to `rocket` crate integration k::integration Related to integration with third-party libraries or systems labels Nov 24, 2023
tyranron added a commit that referenced this issue Nov 24, 2023
- rework `rocket_server` example as `simple`
- provide example in `GraphQLRequest` API docs
- mention GET query format in  `GraphQLRequest` API docs and `simple` example

Additionally:
- fix `operationName` query parameter handling
- make `graphiql_source()` and `playground_source()` polymorphic over `subscriptions_endpoint_url` argument
- provide examples in `graphiql_source()` and `playground_source()` API docs
- move integration HTTP tests to a separate file
- test both sync and async `juniper_rocket` in integration HTTP tests
- polish `FromForm` unit tests
@tyranron
Copy link
Member

@ysulyma the example was fixed, and now mentions the GET request query format:

// GET request accepts query parameters like these:
// ?query=<urlencoded-graphql-query-string>
// &operationName=<optional-name>
// &variables=<optional-json-encoded-variables>
// See details here: https://graphql.org/learn/serving-over-http#get-request
#[rocket::get("/graphql?<request..>")]
async fn get_graphql(
db: &State<Database>,
request: juniper_rocket::GraphQLRequest,
schema: &State<Schema>,
) -> juniper_rocket::GraphQLResponse {
request.execute(schema, db).await
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Improvement of existing features or bugfix k::documentation Related to project documentation k::example Related to usage examples k::integration Related to integration with third-party libraries or systems lib::rocket Related to `rocket` crate integration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants