I would like to build an application and its recommended to use GraphQl for API,
I am not sure which platform to select and what are the differences.
apollo server vs express-graphql
I need to use TypeScript for the project too. Any good Idea would be appreciated.
The batteries-included apollo-server library uses apollo-server-express under the hood.
While Apollo Server is compatible with any GraphQL client, it is an obvious choice if you are already using Apollo Client in your project. Because of the vibrant Apollo ecosystem and advanced production-ready tooling, Apollo Server is a great choice for larger, more nuanced projects.
Apollo Server is an open-source, spec-compliant GraphQL server that's compatible with any GraphQL client, including Apollo Client. It's the best way to build a production-ready, self-documenting GraphQL API that can use data from any source.
Unfortunately, while I'm sure their platform is great, if you're setting up a fresh GraphQL API you should not start with Apollo. It certainly might be useful later, but on day 1 it's a trap, and you'll make your life simpler and easier if you avoid it entirely.
Both are almost same.
Here are some trends, If you are intrested.
https://www.npmtrends.com/apollo-server-vs-express-graphql-vs-graphql-yoga-vs-prisma-vs-apollo-server-express
Below is the now deleted section from the apollo-server README comparing apollo-server to express-graphql.
Note that some of these arguments do not apply anymore e.g. express-grapqhl is now written in TypeScript. Hence the removal of this section from the README.
One observation is that apollo-server is too bloated, and is slowly showing a lack of maintenance. I would go with express-graphql instead if I were to pick one today. But this is personal preference and you should do your own due diligence.
There's also a community-maintained Koa port of express-graphql, called koa-graphql. Using either express-graphql, or koa-graphql, combined with something like envelop, you can achieve everything, if not more, the Apollo "ecosystem" provides in a more modular manner.
Comparison with
express-graphql
Both Apollo Server and
express-graphql
are GraphQL servers for Node.js, built on top of thegraphql-js
reference implementation, but there are a few key differences:
express-graphql
works with Express and Connect, Apollo Server supports Express, Connect, Hapi, Koa and Restify.- Compared to
express-graphql
, Apollo Server has a simpler interface and supports exactly one way of passing queries.- Apollo Server separates serving GraphiQL (an in-browser IDE for exploring GraphQL) from responding to GraphQL requests.
express-graphql
contains code for parsing HTTP request bodies, Apollo Server leaves that to standard packages like body-parser.- Apollo Server includes an
OperationStore
to easily manage whitelisting.- Apollo Server is built with TypeScript.
application/graphql requests
express-graphql
supports theapplication/graphql
Content-Type for requests, which is an alternative toapplication/json
request with only the query part sent as text. In the same way that we usebodyParser.json
to parseapplication/json
requests for apollo-server, we can usebodyParser.text
plus one extra step in order to also parseapplication/graphql
requests. Here's an example for Express:'body-parser'; import { graphqlExpress } from 'apollo-server-express'; const myGraphQLSchema = // ... define or import your schema here! const helperMiddleware = [ bodyParser.json(), bodyParser.text({ type: 'application/graphql' }), (req, res, next) => { if (req.is('application/graphql')) { req.body = { query: req.body }; } next(); } ]; express() .use('/graphql', ...helperMiddleware, graphqlExpress({ schema: myGraphQLSchema })) .listen(3000); ```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With