-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-mesh/plugin-operation-field-permissions': patch | ||
'@graphql-mesh/types': patch | ||
--- | ||
|
||
New Operation Field Permissions plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@graphql-mesh/plugin-operation-field-permissions", | ||
"version": "0.0.0", | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"typescript": { | ||
"definition": "dist/index.d.ts" | ||
}, | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./*": { | ||
"require": "./dist/*.js", | ||
"import": "./dist/*.mjs" | ||
} | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "Urigo/graphql-mesh", | ||
"directory": "packages/plugins/operation-field-permissions" | ||
}, | ||
"peerDependencies": { | ||
"graphql": "*" | ||
}, | ||
"dependencies": { | ||
"@graphql-mesh/types": "0.83.5", | ||
"@graphql-mesh/cross-helpers": "0.2.6", | ||
"@envelop/operation-field-permissions": "3.6.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable no-new-func */ | ||
import { MeshPlugin, MeshPluginOptions, YamlConfig } from '@graphql-mesh/types'; | ||
import { process } from '@graphql-mesh/cross-helpers'; | ||
import { useOperationFieldPermissions } from '@envelop/operation-field-permissions'; | ||
|
||
export default function useMeshOperationFieldPermissions( | ||
options: MeshPluginOptions<YamlConfig.OperationFieldPermissionsConfig> | ||
): MeshPlugin<any> { | ||
return { | ||
onPluginInit({ addPlugin }) { | ||
addPlugin( | ||
useOperationFieldPermissions({ | ||
getPermissions(context) { | ||
const allowedFields = new Set<string>(); | ||
for (const { if: condition, allow } of options.permissions) { | ||
const ifFn = new Function('context', 'env', 'return ' + condition); | ||
if (ifFn(context, process.env)) { | ||
for (const allowedField of allow) { | ||
allowedFields.add(allowedField); | ||
} | ||
} | ||
} | ||
return allowedFields; | ||
}, | ||
}) | ||
); | ||
}, | ||
}; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/plugins/operation-field-permissions/yaml-config.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
extend type Plugin { | ||
operationFieldPermissions: OperationFieldPermissionsConfig | ||
} | ||
|
||
type OperationFieldPermissionsConfig @md { | ||
permissions: [OperationFieldPermission] | ||
} | ||
|
||
type OperationFieldPermission { | ||
if: String | ||
allow: [String] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
website/src/generated-markdown/OperationFieldPermissionsConfig.generated.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
* `permissions` (type: `Array of Object`): | ||
* `if` (type: `String`) | ||
* `allow` (type: `Array of String`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2072,7 +2072,7 @@ | |
"@envelop/types" "2.4.0" | ||
tslib "2.4.0" | ||
|
||
"@envelop/[email protected]": | ||
"@envelop/[email protected]", "@envelop/extended-validation@^1.9.0": | ||
version "1.9.0" | ||
resolved "https://registry.yarnpkg.com/@envelop/extended-validation/-/extended-validation-1.9.0.tgz#a4634452797177e718302a8645a7c8d5381fe09b" | ||
integrity sha512-Kf0xkTKRuP1XEgHa5Pi8+zaCUGYnFyiGPkb24Z/X1zKd8+s2gtuBmaw6GoROgaBoK0XIE+ZYne7BZCheUqfp+A== | ||
|
@@ -2098,6 +2098,14 @@ | |
dependencies: | ||
tslib "^2.4.0" | ||
|
||
"@envelop/[email protected]": | ||
version "3.6.0" | ||
resolved "https://registry.yarnpkg.com/@envelop/operation-field-permissions/-/operation-field-permissions-3.6.0.tgz#fda6451893d1568baff4edec4bb7ee12a92b644c" | ||
integrity sha512-zAh19EMJ3TLco5OsLW1On3M41zej4lkqKL//gfYGFRtGB2x/Hnuc5/9BIVEDb8l0zmCkD9bqgWHoS3NfEnwB7w== | ||
dependencies: | ||
"@envelop/extended-validation" "^1.9.0" | ||
tslib "^2.4.0" | ||
|
||
"@envelop/parser-cache@^4.4.0", "@envelop/parser-cache@^4.6.0": | ||
version "4.7.0" | ||
resolved "https://registry.yarnpkg.com/@envelop/parser-cache/-/parser-cache-4.7.0.tgz#fc438d8ed390c88fa24bf56da3e4da36f088e3fc" | ||
|