We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch graphql-middleware@6.1.33 for the project I'm working on.
graphql-middleware@6.1.33
Here is the diff that solved my problem:
diff --git a/node_modules/graphql-middleware/dist/applicator.js b/node_modules/graphql-middleware/dist/applicator.js index c80326c..ba4c704 100644 --- a/node_modules/graphql-middleware/dist/applicator.js +++ b/node_modules/graphql-middleware/dist/applicator.js @@ -21,46 +21,43 @@ function parseField(field) { } function applyMiddlewareToField(field, options, middleware) { const parsedField = parseField(field); - if (utils.isMiddlewareWithFragment(middleware) && parsedField.resolve && parsedField.resolve !== graphql.defaultFieldResolver) { - return { - ...parsedField, - fragment: middleware.fragment, - fragments: middleware.fragments, - resolve: wrapResolverInMiddleware(parsedField.resolve, middleware.resolve) - }; - } else if (utils.isMiddlewareWithFragment(middleware) && parsedField.subscribe) { - return { - ...parsedField, - fragment: middleware.fragment, - fragments: middleware.fragments, - subscribe: wrapResolverInMiddleware(parsedField.subscribe, middleware.resolve) - }; - } else if (utils.isMiddlewareResolver(middleware) && parsedField.resolve && parsedField.resolve !== graphql.defaultFieldResolver) { - return { - ...parsedField, - resolve: wrapResolverInMiddleware(parsedField.resolve, middleware) - }; - } else if (utils.isMiddlewareResolver(middleware) && parsedField.subscribe) { - return { - ...parsedField, - subscribe: wrapResolverInMiddleware(parsedField.subscribe, middleware) - }; - } else if (utils.isMiddlewareWithFragment(middleware) && !options.onlyDeclaredResolvers) { - return { - ...parsedField, - fragment: middleware.fragment, - fragments: middleware.fragments, - resolve: wrapResolverInMiddleware(graphql.defaultFieldResolver, middleware.resolve) - }; - } else if (utils.isMiddlewareResolver(middleware) && !options.onlyDeclaredResolvers) { - return { - ...parsedField, - resolve: wrapResolverInMiddleware(graphql.defaultFieldResolver, middleware) - }; + + const resolve = options.onlyDeclaredResolvers ? + (field.resolve !== graphql_1.defaultFieldResolver ? parsedField.resolve : null) : + (field.resolve || graphql_1.defaultFieldResolver) + + const subscribe = parsedField.subscribe + + if (resolve || subscribe) { + let update = null + let middlewareResolve = null + + if (utils.isMiddlewareWithFragment(middleware)) { + update = {} + update.fragment = middleware.fragment + update.fragments = middleware.fragments + middlewareResolve = middleware.resolve + } else if (utils.isMiddlewareResolver(middleware)) { + update = {} + middlewareResolve = middleware + } + + if (middlewareResolve) { + if (resolve) { + update.resolve = wrapResolverInMiddleware(resolve, middlewareResolve) + } + if (subscribe) { + update.subscribe = wrapResolverInMiddleware(subscribe, middlewareResolve) + } + return {...parsedField, ...update} + } else { + return parsedField + } } else { - return { ...parsedField, resolve: graphql.defaultFieldResolver }; + return parsedField } } + function applyMiddlewareToType(type, options, middleware) { const fieldMap = type.getFields(); if (utils.isMiddlewareFunction(middleware)) {
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered:
Thanks for this, it appears to work for me. Would you consider putting up a PR?
Sorry, something went wrong.
No branches or pull requests
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
graphql-middleware@6.1.33
for the project I'm working on.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: