-2

I am introducing my self to serverless and stumbled upon this: https://github.com/serverless-components/express and can't seem to understand what's difference with serverfull deployed to heroku? see i have this code in serverless:

app.use(
  "/graphql",
  graphqlHTTP(async (request) => {
    // add user context
    console.log("test");
    return {
      schema,
      graphiql: true,
      context: {
        request,
        //user
      },
    };
  })
);

module.exports = app;

and serverfull:

app.use(
  "/graphql",
  graphqlHTTP(async (request) => {
    // add user context
    return {
      schema,
      graphiql: true,
      context: {
        request,
      },
    };
  })
);

app.listen(port, () => console.log(`Listening on port ${port}`));

can somebody tell me if there's an advantage using serverless in express-graphql? my frontend stack is graphql-relay and i am used to express-graphql and want to explore serverless using express-graphql stack but can't seem to find a good resource to do it. as i am reading from this:

At this point, I think it’s worth noting that not everyone agrees that running Express in a serverless function is a good idea. As Paul Johnston explains, if you’re building your functions for scale, it’s best to break each piece of functionality out into its own single-purpose function. Using Express the way I have means that every time a request goes to the API, the whole Express server has to be booted up from scratch — not very efficient. Deploy to production at your own risk.

please clarify me

gpbaculio
  • 3,649
  • 7
  • 31
  • 67

1 Answers1

2

Some of the benefits of serverless: you execute your code on-demand only when it's needed in contrast to the traditional servers that will be running 24/7. In addition, it also managed by a service provider so you won't need to worry about maintaining and scaling your server.

You can read more

https://dashbird.io/blog/business-benefits-of-serverless/#:~:text=A%20company%20that%20can%20draw,will%20improve%20the%20user%20experience.

https://www.serverless.com/blog/running-scalable-reliable-graphql-endpoint-with-serverless

https://aws.amazon.com/serverless/

https://serverless.com/blog/serverless-architecture-code-patterns/