@envelop/operation-field-permissions 3.4.0-alpha-e9434aa.0 → 3.4.0-alpha-05dbec7.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.
Files changed (2) hide show
  1. package/esm/index.js +13 -17
  2. package/package.json +3 -3
package/esm/index.js CHANGED
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useOperationFieldPermissions = void 0;
4
- const core_1 = require("@envelop/core");
5
- const extended_validation_1 = require("@envelop/extended-validation");
6
- const graphql_1 = require("graphql");
1
+ import { EnvelopError, useExtendContext } from '@envelop/core';
2
+ import { useExtendedValidation } from '@envelop/extended-validation';
3
+ import { isUnionType, isObjectType, isInterfaceType, isIntrospectionType, getNamedType, } from 'graphql';
7
4
  const OPERATION_PERMISSIONS_SYMBOL = Symbol('OPERATION_PERMISSIONS_SYMBOL');
8
5
  /**
9
6
  * Returns a set of type names that allow access to all fields in the type.
@@ -38,7 +35,7 @@ const OperationScopeRule = (options) => (context, executionArgs) => {
38
35
  // TODO: EnvelopError was a bad idea ;)
39
36
  // We should use GraphQLError once the object constructor lands in stable GraphQL.js
40
37
  // and useMaskedErrors supports it.
41
- const error = new core_1.EnvelopError(options.formatError(schemaCoordinate));
38
+ const error = new EnvelopError(options.formatError(schemaCoordinate));
42
39
  error.nodes = [node];
43
40
  context.reportError(error);
44
41
  }
@@ -47,31 +44,31 @@ const OperationScopeRule = (options) => (context, executionArgs) => {
47
44
  Field(node) {
48
45
  const type = context.getType();
49
46
  if (type) {
50
- const namedType = (0, graphql_1.getNamedType)(type);
51
- if ((0, graphql_1.isIntrospectionType)(namedType)) {
47
+ const namedType = getNamedType(type);
48
+ if (isIntrospectionType(namedType)) {
52
49
  return false;
53
50
  }
54
51
  }
55
52
  const parentType = context.getParentType();
56
53
  if (parentType) {
57
- if ((0, graphql_1.isIntrospectionType)(parentType)) {
54
+ if (isIntrospectionType(parentType)) {
58
55
  return false;
59
56
  }
60
57
  // We handle objects, interface and union permissions differently.
61
58
  // When accessing an an object field, we check simply run the check.
62
- if ((0, graphql_1.isObjectType)(parentType)) {
59
+ if (isObjectType(parentType)) {
63
60
  handleField(node, parentType);
64
61
  }
65
62
  // To allow a union case, every type in the union has to be allowed/
66
63
  // If one of the types doesn't permit access we should throw a validation error.
67
- if ((0, graphql_1.isUnionType)(parentType)) {
64
+ if (isUnionType(parentType)) {
68
65
  for (const objectType of parentType.getTypes()) {
69
66
  handleField(node, objectType);
70
67
  }
71
68
  }
72
69
  // Same goes for interfaces. Every implementation should allow the access of the given
73
70
  // field to pass the validation rule.
74
- if ((0, graphql_1.isInterfaceType)(parentType)) {
71
+ if (isInterfaceType(parentType)) {
75
72
  for (const objectType of executionArgs.schema.getImplementations(parentType).objects) {
76
73
  handleField(node, objectType);
77
74
  }
@@ -82,18 +79,18 @@ const OperationScopeRule = (options) => (context, executionArgs) => {
82
79
  };
83
80
  };
84
81
  const defaultFormatError = (schemaCoordinate) => `Insufficient permissions for selecting '${schemaCoordinate}'.`;
85
- const useOperationFieldPermissions = (opts) => {
82
+ export const useOperationFieldPermissions = (opts) => {
86
83
  return {
87
84
  onPluginInit({ addPlugin }) {
88
85
  var _a;
89
- addPlugin((0, extended_validation_1.useExtendedValidation)({
86
+ addPlugin(useExtendedValidation({
90
87
  rules: [
91
88
  OperationScopeRule({
92
89
  formatError: (_a = opts.formatError) !== null && _a !== void 0 ? _a : defaultFormatError,
93
90
  }),
94
91
  ],
95
92
  }));
96
- addPlugin((0, core_1.useExtendContext)(async (context) => {
93
+ addPlugin(useExtendContext(async (context) => {
97
94
  const permissions = await opts.getPermissions(context);
98
95
  // Schema coordinates is a set of type-name field-name strings that
99
96
  // describe the position of a field in the schema.
@@ -111,4 +108,3 @@ const useOperationFieldPermissions = (opts) => {
111
108
  },
112
109
  };
113
110
  };
114
- exports.useOperationFieldPermissions = useOperationFieldPermissions;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@envelop/operation-field-permissions",
3
- "version": "3.4.0-alpha-e9434aa.0",
3
+ "version": "3.4.0-alpha-05dbec7.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-e9434aa.0",
6
+ "@envelop/core": "2.4.0-alpha-05dbec7.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@envelop/extended-validation": "1.7.0-alpha-e9434aa.0"
10
+ "@envelop/extended-validation": "1.7.0-alpha-05dbec7.0"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",