@graphql-mesh/plugin-operation-field-permissions 0.0.1-alpha-20220914154244-6962e2f8a

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/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
2
+ export default function useMeshOperationFieldPermissions(options: MeshPluginOptions<YamlConfig.OperationFieldPermissionsConfig>): MeshPlugin<any>;
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const crossHelpers = require('@graphql-mesh/cross-helpers');
4
+ const operationFieldPermissions = require('@envelop/operation-field-permissions');
5
+
6
+ function useMeshOperationFieldPermissions(options) {
7
+ return {
8
+ onPluginInit({ addPlugin }) {
9
+ addPlugin(operationFieldPermissions.useOperationFieldPermissions({
10
+ getPermissions(context) {
11
+ const allowedFields = new Set();
12
+ for (const { if: condition, allow } of options.permissions) {
13
+ const ifFn = new Function('context', 'env', 'return ' + condition);
14
+ if (ifFn(context, crossHelpers.process.env)) {
15
+ for (const allowedField of allow) {
16
+ allowedFields.add(allowedField);
17
+ }
18
+ }
19
+ }
20
+ return allowedFields;
21
+ },
22
+ }));
23
+ },
24
+ };
25
+ }
26
+
27
+ module.exports = useMeshOperationFieldPermissions;
package/index.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import { process } from '@graphql-mesh/cross-helpers';
2
+ import { useOperationFieldPermissions } from '@envelop/operation-field-permissions';
3
+
4
+ function useMeshOperationFieldPermissions(options) {
5
+ return {
6
+ onPluginInit({ addPlugin }) {
7
+ addPlugin(useOperationFieldPermissions({
8
+ getPermissions(context) {
9
+ const allowedFields = new Set();
10
+ for (const { if: condition, allow } of options.permissions) {
11
+ const ifFn = new Function('context', 'env', 'return ' + condition);
12
+ if (ifFn(context, process.env)) {
13
+ for (const allowedField of allow) {
14
+ allowedFields.add(allowedField);
15
+ }
16
+ }
17
+ }
18
+ return allowedFields;
19
+ },
20
+ }));
21
+ },
22
+ };
23
+ }
24
+
25
+ export default useMeshOperationFieldPermissions;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@graphql-mesh/plugin-operation-field-permissions",
3
+ "version": "0.0.1-alpha-20220914154244-6962e2f8a",
4
+ "sideEffects": false,
5
+ "peerDependencies": {
6
+ "graphql": "*"
7
+ },
8
+ "dependencies": {
9
+ "@envelop/operation-field-permissions": "3.6.0",
10
+ "@graphql-mesh/cross-helpers": "0.2.6",
11
+ "@graphql-mesh/types": "0.83.6-alpha-20220914154244-6962e2f8a",
12
+ "tslib": "^2.4.0"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "Urigo/graphql-mesh",
17
+ "directory": "packages/plugins/operation-field-permissions"
18
+ },
19
+ "license": "MIT",
20
+ "main": "index.js",
21
+ "module": "index.mjs",
22
+ "typings": "index.d.ts",
23
+ "typescript": {
24
+ "definition": "index.d.ts"
25
+ },
26
+ "exports": {
27
+ ".": {
28
+ "require": "./index.js",
29
+ "import": "./index.mjs"
30
+ },
31
+ "./*": {
32
+ "require": "./*.js",
33
+ "import": "./*.mjs"
34
+ },
35
+ "./package.json": "./package.json"
36
+ }
37
+ }