prisma-labs / yoga2

A lightweight 'Ruby on Rails'-like framework for GraphQL
https://www.graphql.yoga
MIT License
347 stars 15 forks source link

Split server into multiple serverless functions #26

Open mxstbr opened 5 years ago

mxstbr commented 5 years ago

Is your feature request related to a problem? Please describe. I have to deploy my entire GraphQL server to a single lambda.

Describe the solution you'd like I want to deploy individual resolvers (or potentially groups of resolvers) to separate lambdas, allowing me to scale them individually.

Describe alternatives you've considered N/A

Additional context It would be great if this worked out of the box with now.sh (cc @rauchg), and there is a recent project that makes this possible: https://graphql-modules.com

pantharshit00 commented 5 years ago

TL;DR

I think in the current state graphql is not ready for serverless as there is no efficient mechanism to route the requests into respective lambdas.

Also, graphql-modules can only split the schema into multiple files but I don't think this solves any kind of routing issue that graphql currently have for a serverless environment.


I was thinking about how we can implement this but I came into some general concerns.

The main concern is how can effectively implement the single /graphql endpoint and run the right lambda for the query without parsing the query multiple times.

The concern is that how we can implement a good api gateway. We can surely parse the query in a master server but that defies the gain we get by this approach as that query parsing overhead is not worth it in my opinion.

In a rest service, we can route requests very easily using the endpoint but in graphql, there is no definitive spec right now and parsing the query multiple time should not be an option here.

So we have three options here(there can be more):

Option 1 - Parse the query once in the master loadbalancer and forward the parsed document to sub lambdas

In this approach, we can group some set of types and queries and forward them accordingly to the appropriate lambda.

Option 2 - Forward the query to the worker server without parsing using some kind of metadata from the frontend

In this approach, we can have some kind of meta from the frontend that the query belong to x lambda and we can invoke that lambda accordingly.

Option 3 - Provide and multiple endpoints to frontend and it will decide to which graphql endpoint a query belongs

I don't personally think this will well worth it as graphql is all about that one endpoint.

Other concerns

I think this a lot more work than we can do right now.

swolidity commented 5 years ago

I wonder if the new Apollo Federation solves the serverless graphql problem https://blog.apollographql.com/apollo-federation-f260cf525d21