View profile

GraphQL vs Express - What's the Difference?

GraphQL vs Express - What's the Difference?
By Mastering JS Weekly • Issue #24 • View online
Express and GraphQL are two different tools for building APIs in Node.js. They aren’t necessarily mutually exclusive. For example, Apollo has a guide to integrating with Express, so you can build a GraphQL API on top of Express. So what should you consider when choosing Express vs Apollo?

Express is More Flexible
Express can be used for much more than just building a JSON API. Express has built-in support for templating engines, so you can build a classical web apps with Express as well as single page apps. Express also makes it easy to built websocket-based or server-sent event based APIs.
By giving you easy access to the raw underlying HTTP request, you can do more with Express than you can with Apollo.
Apollo Gives API Clients More Out of the Box
If you are building a simple JSON API with no need for templating engines or websockets, Apollo and GraphQL give you more neat features out of the box. The key benefit of GraphQL is a structured description of all the methods your API supports, so GraphQL clients can easily see what functionality they can access and what parameters to pass in.
Figuring out exactly what endpoints an Express app supports can be tricky. And even if you have good docs for your API endpoints, it is even harder to get your API endpoint structure into VS Code. GraphQL makes that much easier.
Why Not Both?
You can get the benefits of both by using apollo-server-express. You can mount a GraphQL API as Express middleware, so you get all the documentation and client integrations of GraphQL. But then you can also handle socket upgrades and template engines.
Most Recent Tutorials
Did you enjoy this issue?
Mastering JS Weekly

Pragmatic web development. No bloatware allowed!

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue