@envelop/graphql-middleware 3.4.0-alpha-aca44e1.0 → 3.4.0-alpha-e9434aa.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGraphQLMiddleware = void 0;
4
+ const graphql_middleware_1 = require("graphql-middleware");
5
+ const graphqlMiddlewareAppliedTransformSymbol = Symbol('graphqlMiddleware.appliedTransform');
6
+ const useGraphQLMiddleware = (middlewares) => {
7
+ return {
8
+ onSchemaChange({ schema, replaceSchema }) {
9
+ var _a;
10
+ // @ts-expect-error See https://github.com/graphql/graphql-js/pull/3511 - remove this comments once merged
11
+ if ((_a = schema.extensions) === null || _a === void 0 ? void 0 : _a[graphqlMiddlewareAppliedTransformSymbol]) {
12
+ return;
13
+ }
14
+ if (middlewares.length > 0) {
15
+ const wrappedSchema = (0, graphql_middleware_1.applyMiddleware)(schema, ...middlewares);
16
+ wrappedSchema.extensions = {
17
+ ...schema.extensions,
18
+ [graphqlMiddlewareAppliedTransformSymbol]: true,
19
+ };
20
+ replaceSchema(wrappedSchema);
21
+ }
22
+ },
23
+ };
24
+ };
25
+ exports.useGraphQLMiddleware = useGraphQLMiddleware;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/esm/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGraphQLMiddleware = void 0;
4
+ const graphql_middleware_1 = require("graphql-middleware");
5
+ const graphqlMiddlewareAppliedTransformSymbol = Symbol('graphqlMiddleware.appliedTransform');
6
+ const useGraphQLMiddleware = (middlewares) => {
7
+ return {
8
+ onSchemaChange({ schema, replaceSchema }) {
9
+ var _a;
10
+ // @ts-expect-error See https://github.com/graphql/graphql-js/pull/3511 - remove this comments once merged
11
+ if ((_a = schema.extensions) === null || _a === void 0 ? void 0 : _a[graphqlMiddlewareAppliedTransformSymbol]) {
12
+ return;
13
+ }
14
+ if (middlewares.length > 0) {
15
+ const wrappedSchema = (0, graphql_middleware_1.applyMiddleware)(schema, ...middlewares);
16
+ wrappedSchema.extensions = {
17
+ ...schema.extensions,
18
+ [graphqlMiddlewareAppliedTransformSymbol]: true,
19
+ };
20
+ replaceSchema(wrappedSchema);
21
+ }
22
+ },
23
+ };
24
+ };
25
+ exports.useGraphQLMiddleware = useGraphQLMiddleware;
package/package.json CHANGED
@@ -1,34 +1,56 @@
1
1
  {
2
2
  "name": "@envelop/graphql-middleware",
3
- "version": "3.4.0-alpha-aca44e1.0",
3
+ "version": "3.4.0-alpha-e9434aa.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-aca44e1.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
8
- "graphql-middleware": "^6.0.0"
6
+ "@envelop/core": "2.4.0-alpha-e9434aa.0",
7
+ "graphql-middleware": "^6.0.0",
8
+ "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
9
9
  },
10
+ "dependencies": {},
10
11
  "repository": {
11
12
  "type": "git",
12
- "url": "https://github.com/dotansimha/envelop.git",
13
+ "url": "https://github.com/n1ru4l/envelop.git",
13
14
  "directory": "packages/plugins/graphql-middleware"
14
15
  },
15
16
  "author": "Dotan Simha <dotansimha@gmail.com>",
16
17
  "license": "MIT",
17
- "main": "index.js",
18
- "module": "index.mjs",
19
- "typings": "index.d.ts",
18
+ "main": "cjs/index.js",
19
+ "module": "esm/index.js",
20
+ "typings": "typings/index.d.ts",
20
21
  "typescript": {
21
- "definition": "index.d.ts"
22
+ "definition": "typings/index.d.ts"
22
23
  },
24
+ "type": "module",
23
25
  "exports": {
24
26
  ".": {
25
- "require": "./index.js",
26
- "import": "./index.mjs"
27
+ "require": {
28
+ "types": "./typings/index.d.ts",
29
+ "default": "./cjs/index.js"
30
+ },
31
+ "import": {
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./esm/index.js"
34
+ },
35
+ "default": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ }
27
39
  },
28
40
  "./*": {
29
- "require": "./*.js",
30
- "import": "./*.mjs"
41
+ "require": {
42
+ "types": "./typings/*.d.ts",
43
+ "default": "./cjs/*.js"
44
+ },
45
+ "import": {
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./esm/*.js"
48
+ },
49
+ "default": {
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
52
+ }
31
53
  },
32
54
  "./package.json": "./package.json"
33
55
  }
34
- }
56
+ }
File without changes
package/README.md DELETED
@@ -1,44 +0,0 @@
1
- ## `@envelop/graphql-middleware`
2
-
3
- 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`.
4
-
5
- > You can find an awesome [list of middlewares here](https://github.com/maticzav/graphql-middleware#awesome-middlewares-)
6
-
7
- ## Getting Started
8
-
9
- ```
10
- yarn add graphql-middleware @envelop/graphql-middleware
11
- ```
12
-
13
- ## Usage Example
14
-
15
- You can use any type of middleware defined for `graphql-middleware`, here's an example for doing that with [`graphql-shield`](https://github.com/maticzav/graphql-shield):
16
-
17
- ```ts
18
- import { envelop } from '@envelop/core';
19
- import { useGraphQLMiddleware } from '@envelop/graphql-middleware';
20
- import { rule, shield, and, or, not } from 'graphql-shield';
21
-
22
- // ...
23
- // You can find a complete example here: https://github.com/maticzav/graphql-shield#graphql-yoga
24
- // ...
25
-
26
- const permissions = shield({
27
- Query: {
28
- fruits: and(isAuthenticated, or(isAdmin, isEditor)),
29
- },
30
- Mutation: {
31
- addFruitToBasket: isAuthenticated,
32
- },
33
- Fruit: isAuthenticated,
34
- Customer: isAdmin,
35
- });
36
-
37
- const getEnveloped = envelop({
38
- plugins: [
39
- // ... other plugins ...
40
- useSchema(mySchema),
41
- useGraphQLMiddleware([permissions]),
42
- ],
43
- });
44
- ```
package/index.js DELETED
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const graphqlMiddleware = require('graphql-middleware');
6
-
7
- const middlewaresAppliedSymbol = Symbol('SCHEMA_WITH_MIDDLEWARES');
8
- const useGraphQLMiddleware = (middlewares) => {
9
- return {
10
- onSchemaChange({ schema, replaceSchema }) {
11
- if (schema[middlewaresAppliedSymbol]) {
12
- return;
13
- }
14
- if (middlewares.length > 0) {
15
- const wrappedSchema = graphqlMiddleware.applyMiddleware(schema, ...middlewares);
16
- wrappedSchema[middlewaresAppliedSymbol] = true;
17
- replaceSchema(wrappedSchema);
18
- }
19
- },
20
- };
21
- };
22
-
23
- exports.useGraphQLMiddleware = useGraphQLMiddleware;
package/index.mjs DELETED
@@ -1,19 +0,0 @@
1
- import { applyMiddleware } from 'graphql-middleware';
2
-
3
- const middlewaresAppliedSymbol = Symbol('SCHEMA_WITH_MIDDLEWARES');
4
- const useGraphQLMiddleware = (middlewares) => {
5
- return {
6
- onSchemaChange({ schema, replaceSchema }) {
7
- if (schema[middlewaresAppliedSymbol]) {
8
- return;
9
- }
10
- if (middlewares.length > 0) {
11
- const wrappedSchema = applyMiddleware(schema, ...middlewares);
12
- wrappedSchema[middlewaresAppliedSymbol] = true;
13
- replaceSchema(wrappedSchema);
14
- }
15
- },
16
- };
17
- };
18
-
19
- export { useGraphQLMiddleware };