Search code examples
graphqlexpress-graphql

should I use express-graphql or appolo-server-graphql


I'm working on an express backend that use graphql ajd I don't know if I need to use the express-graphql or appolo-server-graphql lib. Thank you for your help!


Solution

  • I suggest using apollo-server-express over express-graphql. They are very similar, but apollo-server-express has more bells and whistles all while having a simpler and clearer API IMO.

    The biggest improvement in apollo-server-express, for me, is the playground: https://github.com/prisma/graphql-playground

    The playground is better than express-graphql's graphiql for several reasons, but one big one is that it allows you to put HTTP headers in the request, which is more appropriate for handling session.

    www.graphqlbin.com will allow you to use the playground on any endpoint which does not have cors. If you have cors, then you will need to run playground directly from your server.

    Here is a sample of code to get you started:

    const { ApolloServer } = require('apollo-server-express')
    const graphqlServer = new ApolloServer({
      schema,
      introspection: true,
      playground: true,
    })
    graphqlServer.applyMiddleware({
      app
    })