-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A better apollo integration #27
Comments
This is a lot cleaner than the current implementation, thank you for doing this! I didn't realize Apollo directly allows rewriting responses like this so easily. Pending resolution of #28, I'll get a repo set up either in this org or in a new org and work on getting this merged! |
I faced an issue with the response, it duplicates the response payload for some reason for arrays. DO NOT USE until I fix it. |
Fixed in #29 |
This implementation has worked well for us, notably overcoming graphql-query-rewriter/express-graphql-query-rewriter#6 However, it has one important bug: it throws an error within Fixed by adding a one-line check: 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
if (!response.data) return
const newData = handler.rewriteResponse(response.data)
response.data = newData
},
}
},
}) An alternative fix would be to update |
Thanks for that, I will create an official package when I have time |
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:
The text was updated successfully, but these errors were encountered: