@envelop/operation-field-permissions 1.1.0-alpha-6952fd9.0 → 1.1.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/index.js +17 -10
- package/index.mjs +19 -12
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -34,9 +34,6 @@ const getContext = (input) => {
|
|
|
34
34
|
* Validate whether a user is allowed to execute a certain GraphQL operation.
|
|
35
35
|
*/
|
|
36
36
|
const OperationScopeRule = (options) => (context, executionArgs) => {
|
|
37
|
-
if (core.isIntrospectionDocument(executionArgs.document)) {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
37
|
const permissionContext = getContext(executionArgs.contextValue);
|
|
41
38
|
const handleField = (node, objectType) => {
|
|
42
39
|
const schemaCoordinate = `${objectType.name}.${node.name.value}`;
|
|
@@ -48,23 +45,33 @@ const OperationScopeRule = (options) => (context, executionArgs) => {
|
|
|
48
45
|
};
|
|
49
46
|
return {
|
|
50
47
|
Field(node) {
|
|
48
|
+
const type = context.getType();
|
|
49
|
+
if (type) {
|
|
50
|
+
const wrappedType = getWrappedType(type);
|
|
51
|
+
if (graphql.isIntrospectionType(wrappedType)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
51
55
|
const parentType = context.getParentType();
|
|
52
56
|
if (parentType) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
if (graphql.isIntrospectionType(parentType)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if (graphql.isObjectType(parentType)) {
|
|
61
|
+
handleField(node, parentType);
|
|
56
62
|
}
|
|
57
|
-
else if (graphql.isUnionType(
|
|
58
|
-
for (const objectType of
|
|
63
|
+
else if (graphql.isUnionType(parentType)) {
|
|
64
|
+
for (const objectType of parentType.getTypes()) {
|
|
59
65
|
handleField(node, objectType);
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
|
-
else if (graphql.isInterfaceType(
|
|
63
|
-
for (const objectType of executionArgs.schema.getImplementations(
|
|
68
|
+
else if (graphql.isInterfaceType(parentType)) {
|
|
69
|
+
for (const objectType of executionArgs.schema.getImplementations(parentType).objects) {
|
|
64
70
|
handleField(node, objectType);
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
}
|
|
74
|
+
return undefined;
|
|
68
75
|
},
|
|
69
76
|
};
|
|
70
77
|
};
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useExtendContext } from '@envelop/core';
|
|
2
2
|
import { useExtendedValidation } from '@envelop/extended-validation';
|
|
3
|
-
import { isObjectType, isUnionType, isInterfaceType, GraphQLList, GraphQLNonNull, GraphQLError } from 'graphql';
|
|
3
|
+
import { isIntrospectionType, isObjectType, isUnionType, isInterfaceType, GraphQLList, GraphQLNonNull, GraphQLError } from 'graphql';
|
|
4
4
|
|
|
5
5
|
const getWrappedType = (graphqlType) => {
|
|
6
6
|
if (graphqlType instanceof GraphQLList || graphqlType instanceof GraphQLNonNull) {
|
|
@@ -30,9 +30,6 @@ const getContext = (input) => {
|
|
|
30
30
|
* Validate whether a user is allowed to execute a certain GraphQL operation.
|
|
31
31
|
*/
|
|
32
32
|
const OperationScopeRule = (options) => (context, executionArgs) => {
|
|
33
|
-
if (isIntrospectionDocument(executionArgs.document)) {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
33
|
const permissionContext = getContext(executionArgs.contextValue);
|
|
37
34
|
const handleField = (node, objectType) => {
|
|
38
35
|
const schemaCoordinate = `${objectType.name}.${node.name.value}`;
|
|
@@ -44,23 +41,33 @@ const OperationScopeRule = (options) => (context, executionArgs) => {
|
|
|
44
41
|
};
|
|
45
42
|
return {
|
|
46
43
|
Field(node) {
|
|
44
|
+
const type = context.getType();
|
|
45
|
+
if (type) {
|
|
46
|
+
const wrappedType = getWrappedType(type);
|
|
47
|
+
if (isIntrospectionType(wrappedType)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
47
51
|
const parentType = context.getParentType();
|
|
48
52
|
if (parentType) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (isIntrospectionType(parentType)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (isObjectType(parentType)) {
|
|
57
|
+
handleField(node, parentType);
|
|
52
58
|
}
|
|
53
|
-
else if (isUnionType(
|
|
54
|
-
for (const objectType of
|
|
59
|
+
else if (isUnionType(parentType)) {
|
|
60
|
+
for (const objectType of parentType.getTypes()) {
|
|
55
61
|
handleField(node, objectType);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
|
-
else if (isInterfaceType(
|
|
59
|
-
for (const objectType of executionArgs.schema.getImplementations(
|
|
64
|
+
else if (isInterfaceType(parentType)) {
|
|
65
|
+
for (const objectType of executionArgs.schema.getImplementations(parentType).objects) {
|
|
60
66
|
handleField(node, objectType);
|
|
61
67
|
}
|
|
62
68
|
}
|
|
63
69
|
}
|
|
70
|
+
return undefined;
|
|
64
71
|
},
|
|
65
72
|
};
|
|
66
73
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/operation-field-permissions",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@envelop/core": "1.5.0
|
|
10
|
-
"@envelop/extended-validation": "1.2.0
|
|
9
|
+
"@envelop/core": "1.5.0",
|
|
10
|
+
"@envelop/extended-validation": "1.2.0"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|