1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.isDirective = isDirective;
|
7 | exports.assertDirective = assertDirective;
|
8 | exports.isSpecifiedDirective = isSpecifiedDirective;
|
9 | exports.specifiedDirectives = exports.GraphQLSpecifiedByDirective = exports.GraphQLDeprecatedDirective = exports.DEFAULT_DEPRECATION_REASON = exports.GraphQLSkipDirective = exports.GraphQLIncludeDirective = exports.GraphQLDirective = void 0;
|
10 |
|
11 | var _objectEntries = _interopRequireDefault(require("../polyfills/objectEntries.js"));
|
12 |
|
13 | var _symbols = require("../polyfills/symbols.js");
|
14 |
|
15 | var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
|
16 |
|
17 | var _toObjMap = _interopRequireDefault(require("../jsutils/toObjMap.js"));
|
18 |
|
19 | var _devAssert = _interopRequireDefault(require("../jsutils/devAssert.js"));
|
20 |
|
21 | var _instanceOf = _interopRequireDefault(require("../jsutils/instanceOf.js"));
|
22 |
|
23 | var _isObjectLike = _interopRequireDefault(require("../jsutils/isObjectLike.js"));
|
24 |
|
25 | var _defineInspect = _interopRequireDefault(require("../jsutils/defineInspect.js"));
|
26 |
|
27 | var _directiveLocation = require("../language/directiveLocation.js");
|
28 |
|
29 | var _scalars = require("./scalars.js");
|
30 |
|
31 | var _definition = require("./definition.js");
|
32 |
|
33 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
34 |
|
35 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
36 |
|
37 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
38 |
|
39 |
|
40 | function isDirective(directive) {
|
41 | return (0, _instanceOf.default)(directive, GraphQLDirective);
|
42 | }
|
43 |
|
44 | function assertDirective(directive) {
|
45 | if (!isDirective(directive)) {
|
46 | throw new Error("Expected ".concat((0, _inspect.default)(directive), " to be a GraphQL directive."));
|
47 | }
|
48 |
|
49 | return directive;
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var GraphQLDirective = function () {
|
58 | function GraphQLDirective(config) {
|
59 | var _config$isRepeatable, _config$args;
|
60 |
|
61 | this.name = config.name;
|
62 | this.description = config.description;
|
63 | this.locations = config.locations;
|
64 | this.isRepeatable = (_config$isRepeatable = config.isRepeatable) !== null && _config$isRepeatable !== void 0 ? _config$isRepeatable : false;
|
65 | this.extensions = config.extensions && (0, _toObjMap.default)(config.extensions);
|
66 | this.astNode = config.astNode;
|
67 | config.name || (0, _devAssert.default)(0, 'Directive must be named.');
|
68 | Array.isArray(config.locations) || (0, _devAssert.default)(0, "@".concat(config.name, " locations must be an Array."));
|
69 | var args = (_config$args = config.args) !== null && _config$args !== void 0 ? _config$args : {};
|
70 | (0, _isObjectLike.default)(args) && !Array.isArray(args) || (0, _devAssert.default)(0, "@".concat(config.name, " args must be an object with argument names as keys."));
|
71 | this.args = (0, _objectEntries.default)(args).map(function (_ref) {
|
72 | var argName = _ref[0],
|
73 | argConfig = _ref[1];
|
74 | return {
|
75 | name: argName,
|
76 | description: argConfig.description,
|
77 | type: argConfig.type,
|
78 | defaultValue: argConfig.defaultValue,
|
79 | deprecationReason: argConfig.deprecationReason,
|
80 | extensions: argConfig.extensions && (0, _toObjMap.default)(argConfig.extensions),
|
81 | astNode: argConfig.astNode
|
82 | };
|
83 | });
|
84 | }
|
85 |
|
86 | var _proto = GraphQLDirective.prototype;
|
87 |
|
88 | _proto.toConfig = function toConfig() {
|
89 | return {
|
90 | name: this.name,
|
91 | description: this.description,
|
92 | locations: this.locations,
|
93 | args: (0, _definition.argsToArgsConfig)(this.args),
|
94 | isRepeatable: this.isRepeatable,
|
95 | extensions: this.extensions,
|
96 | astNode: this.astNode
|
97 | };
|
98 | };
|
99 |
|
100 | _proto.toString = function toString() {
|
101 | return '@' + this.name;
|
102 | };
|
103 |
|
104 | _proto.toJSON = function toJSON() {
|
105 | return this.toString();
|
106 | }
|
107 | ;
|
108 |
|
109 | _createClass(GraphQLDirective, [{
|
110 | key: _symbols.SYMBOL_TO_STRING_TAG,
|
111 | get: function get() {
|
112 | return 'GraphQLDirective';
|
113 | }
|
114 | }]);
|
115 |
|
116 | return GraphQLDirective;
|
117 | }();
|
118 |
|
119 |
|
120 | exports.GraphQLDirective = GraphQLDirective;
|
121 | (0, _defineInspect.default)(GraphQLDirective);
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | var GraphQLIncludeDirective = new GraphQLDirective({
|
127 | name: 'include',
|
128 | description: 'Directs the executor to include this field or fragment only when the `if` argument is true.',
|
129 | locations: [_directiveLocation.DirectiveLocation.FIELD, _directiveLocation.DirectiveLocation.FRAGMENT_SPREAD, _directiveLocation.DirectiveLocation.INLINE_FRAGMENT],
|
130 | args: {
|
131 | if: {
|
132 | type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
|
133 | description: 'Included when true.'
|
134 | }
|
135 | }
|
136 | });
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | exports.GraphQLIncludeDirective = GraphQLIncludeDirective;
|
142 | var GraphQLSkipDirective = new GraphQLDirective({
|
143 | name: 'skip',
|
144 | description: 'Directs the executor to skip this field or fragment when the `if` argument is true.',
|
145 | locations: [_directiveLocation.DirectiveLocation.FIELD, _directiveLocation.DirectiveLocation.FRAGMENT_SPREAD, _directiveLocation.DirectiveLocation.INLINE_FRAGMENT],
|
146 | args: {
|
147 | if: {
|
148 | type: new _definition.GraphQLNonNull(_scalars.GraphQLBoolean),
|
149 | description: 'Skipped when true.'
|
150 | }
|
151 | }
|
152 | });
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | exports.GraphQLSkipDirective = GraphQLSkipDirective;
|
158 | var DEFAULT_DEPRECATION_REASON = 'No longer supported';
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | exports.DEFAULT_DEPRECATION_REASON = DEFAULT_DEPRECATION_REASON;
|
164 | var GraphQLDeprecatedDirective = new GraphQLDirective({
|
165 | name: 'deprecated',
|
166 | description: 'Marks an element of a GraphQL schema as no longer supported.',
|
167 | locations: [_directiveLocation.DirectiveLocation.FIELD_DEFINITION, _directiveLocation.DirectiveLocation.ARGUMENT_DEFINITION, _directiveLocation.DirectiveLocation.INPUT_FIELD_DEFINITION, _directiveLocation.DirectiveLocation.ENUM_VALUE],
|
168 | args: {
|
169 | reason: {
|
170 | type: _scalars.GraphQLString,
|
171 | description: 'Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).',
|
172 | defaultValue: DEFAULT_DEPRECATION_REASON
|
173 | }
|
174 | }
|
175 | });
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | exports.GraphQLDeprecatedDirective = GraphQLDeprecatedDirective;
|
181 | var GraphQLSpecifiedByDirective = new GraphQLDirective({
|
182 | name: 'specifiedBy',
|
183 | description: 'Exposes a URL that specifies the behaviour of this scalar.',
|
184 | locations: [_directiveLocation.DirectiveLocation.SCALAR],
|
185 | args: {
|
186 | url: {
|
187 | type: new _definition.GraphQLNonNull(_scalars.GraphQLString),
|
188 | description: 'The URL that specifies the behaviour of this scalar.'
|
189 | }
|
190 | }
|
191 | });
|
192 |
|
193 |
|
194 |
|
195 |
|
196 | exports.GraphQLSpecifiedByDirective = GraphQLSpecifiedByDirective;
|
197 | var specifiedDirectives = Object.freeze([GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective, GraphQLSpecifiedByDirective]);
|
198 | exports.specifiedDirectives = specifiedDirectives;
|
199 |
|
200 | function isSpecifiedDirective(directive) {
|
201 | return specifiedDirectives.some(function (_ref2) {
|
202 | var name = _ref2.name;
|
203 | return name === directive.name;
|
204 | });
|
205 | }
|