-
Notifications
You must be signed in to change notification settings - Fork 66
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
enhancement: support graphql-playground #717
Conversation
@rvmelkonian Thanks for doing this! I'll be reviewing this after I finish up the GraphQL filtering implementation. Regarding the bit about JSON and the formatting for the playground, I wonder if there's an internal option that we can adjust with the playground, as JSON is the most common serialization format for GraphQL and it seems weird that the formatting would be wrong in that way. Otherwise, we would need to make sure that we could go from |
@deekerno I agree it does seem weird. I think that |
@rvmelkonian
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! I had to adjust your testing steps a bit (I ended up using the block explorer example so I didn't have to run a node), but querying works as one would expect. This will be great when filtering and pagination are added.
A few questions that I'd like you to investigate before I approve this, if you don't mind:
- The
HTTP 500
error is being caused by the playground firing an introspection query as soon as it starts. And it actually does it every two seconds until it finally backs off. I've tried setting"schema.polling.enable"
tofalse
as it states in the playground docs, but it doesn't work. I don't think we'll ever support introspection (or not for a long time, at least) and many deployments don't enable it in production. Can you see if you can get it disabled? - The odd coloring may be caused by the fact that we're technically not spec-compliant when it comes to the format of the response; see this section of the latest version of the spec. Successful responses should have their payloads set as the value to the
"data"
key. Would you mind investigating this as well? I'd imagine that's the problem for the formatting, and it would benefit users who use GraphQL clients.
@deekerno @ra0x3
• Answer is yes. NB• One odd thing I noticed, is when I test the old raw query in Postman, I get an error, which is what I would expect. However in our tests, the test client is still accepting the old raw string query. It responds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rvmelkonian
Functionally this works. Played around with it for a bit. Looks good.
Left a few comments regarding Rust stuff. After those changes will ✅
Edit: Actually, we will want to add some docs for this new functionality as well.
- In the book, under the "GraphQL section" we will want to add a new sub-section "9.4 Playground"
- It doesn't have to be a novel, but we just need to mention what the playground is, how it works, and how users can spin it up
.status(StatusCode::OK) | ||
.header(http::header::CONTENT_TYPE, "text/html; charset=utf-8") | ||
.body(Body::from(html)) | ||
.expect("Failed to build gql playground response.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convention: unwrap with ?
.expect("Failed to build gql playground response.") | |
? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to implement the From
method on enums ApiError
and HttpError
in order to satisfy the compiler. This allows us to use ? here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is shaping up to pretty damn nice, if I do say so myself.
Closes #646
Changelog
• Adds the crates
async-graphql
andasync-graphql-axum
.• Adds the new api route
/playground/:namespace/:identifier
.• Adds new handler function for the above route
gql_playground
.• Appends data field to query responses so that playground renders response correctly.
• Updates tests to assert against the new response.
• Updates docs with new query.
• Updates the response type for handler function
query_graph
toGraphQLRequest
.Context
When initially testing querying in Postman, I found that our api would only accept a request of raw string. When I tried to use Postmans GraphQL testing request type, our server could not parse the request. I was able to reproduce this with the Playground, the playground was not functioning as it formats its requests to Graphql Request types. It was safe to assume that any GraphQL client would also not work.
I looked at some other repositories using graphql with the playground they implemented the
async_graphql_axum::GraphQLRequest
type. After doing this, our server was able to parse the queries from a graphQL client.If we want prettier responses with the playground, we would have to update our response types to
async_graphql_axum::GraphQLResponse
, but I thought this was unnecessary for now.Testing
cargo run --bin fuel-node
cargo run --bin fuel-indexer -- run --manifest packages/fuel-indexer-tests/components/indices/fuel-indexer-test/fuel_indexer_test.yaml
http://localhost:29987/api/playground/fuel_indexer_test/index1
(you will see some error on initial render, ignore it).You should receive the response. (If this fails you may need to trigger an event via the web-api so that the DB has some data to query).
For more optional testing you can try deploying a second indexer and using that namespace and identifier to query through the playground, if you like.