@envelop/graphql-middleware
Version:
This plugins wraps [`graphql-middleware`](https://github.com/maticzav/graphql-middleware) and allow you to apply schema middlewares that uses the standard defined by `graphql-middleware`.
24 lines (23 loc) • 957 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useGraphQLMiddleware = void 0;
const graphql_middleware_1 = require("graphql-middleware");
const graphqlMiddlewareAppliedTransformSymbol = Symbol('graphqlMiddleware.appliedTransform');
const useGraphQLMiddleware = (middlewares) => {
return {
onSchemaChange({ schema, replaceSchema }) {
if (schema.extensions?.[graphqlMiddlewareAppliedTransformSymbol]) {
return;
}
if (middlewares.length > 0) {
const wrappedSchema = (0, graphql_middleware_1.applyMiddleware)(schema, ...middlewares);
wrappedSchema.extensions = {
...schema.extensions,
[graphqlMiddlewareAppliedTransformSymbol]: true,
};
replaceSchema(wrappedSchema);
}
},
};
};
exports.useGraphQLMiddleware = useGraphQLMiddleware;
;