-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Now I am not sure where to post that since there doesn't seem to be big community around the project, but I wrote a better integration for apollo:
import { ApolloServerPlugin } from 'apollo-server-plugin-base'
import { RewriteHandler, Rewriter } from 'graphql-query-rewriter'
import { Context } from '~/context'
// An optimization that could be done is avoiding a query parsing
// and reprinting in the input. Not sure how to do this.
export const GraphQLQueryRewriter = (
rewriters: Rewriter[]
): ApolloServerPlugin<Context> => ({
requestDidStart(reqCtx) {
const { request } = reqCtx
const handler = new RewriteHandler(rewriters)
const rewrittenRequest = handler.rewriteRequest(request.query!, request.variables)
request.query = rewrittenRequest.query
request.variables = rewrittenRequest.variables
return {
willSendResponse: resCtx => {
const { response } = resCtx
const newData = handler.rewriteResponse(response.data)
response.data = newData
},
}
},
})Metadata
Metadata
Assignees
Labels
No labels