Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

graphql

apollo

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 (an example: https://medium.com/codingthesmartway-com-blog/apollo-server-2-introduction-efc4026f5654).

In which case should we use it with (or without) integration? What should drive this decision?

like image 248
Aleks Avatar asked May 05 '20 14:05

Aleks


People also ask

Why does Apollo-server-Express?

apollo-server-expressIt enables you to attach a GraphQL server to an existing Express server. The batteries-included apollo-server library uses apollo-server-express under the hood. If you start with apollo-server and later need to modify how it serves over HTTP, you can swap apollo-server to apollo-server-express .

What is Apollo-server-Express?

Apollo Server is a community-maintained open-source GraphQL server that works with many Node. js HTTP server frameworks. Read the docs. Read the CHANGELOG. A full example of how to use apollo-server-express can be found in the docs.

Why do we need Apollo for GraphQL?

Apollo tracks your GraphQL schemas in a registry to create a central source of truth for everything in your supergraph. Studio allows developers to explore data, collaborate on queries, observe usage, and deliver schema changes with agility and confidence.

Does Express work with GraphQL?

The express-graphql module provides a simple way to create an Express server that runs a GraphQL API.


Video Answer


1 Answers

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.

like image 72
Daniel Rearden Avatar answered Sep 20 '22 04:09

Daniel Rearden