Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between apollo server and express-graphql

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.

like image 886
MJ X Avatar asked Oct 28 '19 15:10

MJ X


People also ask

Is Apollo server based on Express?

The batteries-included apollo-server library uses apollo-server-express under the hood.

Which server is best for GraphQL?

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.

What is Apollo server GraphQL?

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.

Can I use GraphQL without Apollo?

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.


2 Answers

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

like image 103
vivek Avatar answered Sep 21 '22 20:09

vivek


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 the graphql-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 the application/graphql Content-Type for requests, which is an alternative to application/json request with only the query part sent as text. In the same way that we use bodyParser.json to parse application/json requests for apollo-server, we can use bodyParser.text plus one extra step in order to also parse application/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); ```
like image 44
jmurzy Avatar answered Sep 19 '22 20:09

jmurzy