Juniper: Add hyper example/integration

Created on 6 Dec 2017  路  9Comments  路  Source: graphql-rust/juniper

I would be great to have a juniper crate (or example) that integrates with "vanilla" hyper

Most helpful comment

My thinking was we have Iron and Rocket integration, but generally don't leverage that many features of them as all the GraphQL queries are on one route and merely passed through to juniper via the framework. Most the stuff Juniper needs (status codes, http method, getting a query string, etc) is in http/hyper. For most standalone GraphQL services merely using Hyper+juniper would likely be sufficient without the added complexity or dependencies of a web framework.

All 9 comments

We can definitely write up an example, probably using https://github.com/alexcrichton/futures-rs for executing the Juniper part.

I think vanilla Hyper might be too edge case or to use-case specific to have an integration crate though.

My thinking was we have Iron and Rocket integration, but generally don't leverage that many features of them as all the GraphQL queries are on one route and merely passed through to juniper via the framework. Most the stuff Juniper needs (status codes, http method, getting a query string, etc) is in http/hyper. For most standalone GraphQL services merely using Hyper+juniper would likely be sufficient without the added complexity or dependencies of a web framework.

@theduke @mhallin Does juniper work w/ [email protected]? All my attempts to run it are failed due to lifetime issues and I'm not sure if it's me or it just doesn't supposed to work.

nvm, it worked

@LegNeato / @theduke I have a first version of the hyper integration crate, which uses https://crates.io/crates/futures-cpupool to execute the request (so that the hyper threads are not blocked). It also includes a running example server. You can find it at:

https://github.com/dvic/juniper/tree/hyper-integration/juniper_hyper

It took me quite a while to get the lifetimes and references working because of the cpu pool. I'd love to receive feedback on the design. E.g., since Hyper does not include a router, it seemed more appropriate to expose public handler functions instead of a single Service implementation. What are your thoughts on this?

I still need to finish a few things:

  • documentation
  • properly rendering the errors (with correct status codes)
  • tests

@dvic that looks great, thanks for working on this! I think the handler functions are sufficient. We could have an entire hyper service but I think it is more flexible the way you currently have it. For bonus points you could add a service as an optional "batteries included" component for those that just want a server with juniper integration quickly.

A couple of small things:

Thanks again for digging into this! 馃嵒

@LegNeato I added the graphiql UI and also the http tests, thanks for the tip! I submitted a WIP PR #230 so discussion can take place there.

https://crates.io/crates/juniper_hyper has now been published! 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

teymour-aldridge picture teymour-aldridge  路  5Comments

skerkour picture skerkour  路  5Comments

thedodd picture thedodd  路  5Comments

projektir picture projektir  路  4Comments

hrbigelow picture hrbigelow  路  5Comments