Why Express (or other integration) with Apollo GraphQL Sever?

前端 未结 1 1679
陌清茗
陌清茗 2021-01-11 22:34

I am struggling to understand the added value of Express (or Koa, Hapi, etc) integration with Apollo GraphQL server.

I see it can work in stand alone mode very well

相关标签:
1条回答
  • 2021-01-11 23:10

    If all you need is a GraphQL endpoint, then using the standalone library (apollo-server) is generally preferred because there will be less boilerplate to write (features like subscriptions, file uploads, etc. just work without additional configuration). However, many applications require additional functionality beyond just exposing a single API endpoint. Examples include:

    • Webhooks
    • OAuth callbacks
    • Session management
    • Cookie parsing
    • CSRF protection
    • Monitoring or logging requests
    • Rate limiting
    • Geofencing
    • Serving static content
    • Server-side rendering

    If you need this sort of functionality for your application, then you'll want to utilize an HTTP framework like Express and then use the appropriate integration library (i.e. apollo-server-express).

    Apollo Server also includes integrations for serverless solutions AWS Lambda. If you want to go serverless to, for example, get better scalability or eliminate system admin costs, then you would also need to use one of these integrations.

    0 讨论(0)
提交回复
热议问题