graphql-query-rewriter / core

Seamlessly turn breaking GraphQL changes into non-breaking changes
https://graphql-query-rewriter.github.io/core
MIT License
409 stars 16 forks source link

Support Apollo Server #2

Closed lorensr closed 5 years ago

lorensr commented 5 years ago

I see in the README that this is planned—just opening this issue to track it ☺️

chanind commented 5 years ago

Thanks for the push on this! Hopefully it should happen in the next week or so

chanind commented 5 years ago

Actually, it looks like ApolloServer already works with express-graphql-query-rewriter using the middleware pattern described in the apollo docs. For example:

const { ApolloServer, gql } = require("apollo-server-express");
const express = require("express");
const { graphqlRewriterMiddleware } = require("express-graphql-query-rewriter");

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
const path = "/graphql";
app.use(
  path,
  graphqlRewriterMiddleware({
    rewriters: [
      // rewriters here as usual
    ]
  })
);
server.applyMiddleware({ app, path, bodyParserConfig: false });

app.listen({ port: 4000 }, () => {
  console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);
});

It seems like the tricky part is passing bodyParserConfig: false, since express-graphql-query-rewriter already parses the body of the request in order to do the rewriting.

chanind commented 5 years ago

I updated the README with instructions for apollo-server, so closing this issue for now