1 | 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); } }
|
2 |
|
3 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
4 |
|
5 | import objectEntries from "../polyfills/objectEntries.mjs";
|
6 | import { SYMBOL_TO_STRING_TAG } from "../polyfills/symbols.mjs";
|
7 | import inspect from "../jsutils/inspect.mjs";
|
8 | import toObjMap from "../jsutils/toObjMap.mjs";
|
9 | import devAssert from "../jsutils/devAssert.mjs";
|
10 | import instanceOf from "../jsutils/instanceOf.mjs";
|
11 | import isObjectLike from "../jsutils/isObjectLike.mjs";
|
12 | import defineInspect from "../jsutils/defineInspect.mjs";
|
13 | import { DirectiveLocation } from "../language/directiveLocation.mjs";
|
14 | import { GraphQLString, GraphQLBoolean } from "./scalars.mjs";
|
15 | import { argsToArgsConfig, GraphQLNonNull } from "./definition.mjs";
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export function isDirective(directive) {
|
22 | return instanceOf(directive, GraphQLDirective);
|
23 | }
|
24 | export function assertDirective(directive) {
|
25 | if (!isDirective(directive)) {
|
26 | throw new Error("Expected ".concat(inspect(directive), " to be a GraphQL directive."));
|
27 | }
|
28 |
|
29 | return directive;
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | export var GraphQLDirective = function () {
|
37 | function GraphQLDirective(config) {
|
38 | var _config$isRepeatable, _config$args;
|
39 |
|
40 | this.name = config.name;
|
41 | this.description = config.description;
|
42 | this.locations = config.locations;
|
43 | this.isRepeatable = (_config$isRepeatable = config.isRepeatable) !== null && _config$isRepeatable !== void 0 ? _config$isRepeatable : false;
|
44 | this.extensions = config.extensions && toObjMap(config.extensions);
|
45 | this.astNode = config.astNode;
|
46 | config.name || devAssert(0, 'Directive must be named.');
|
47 | Array.isArray(config.locations) || devAssert(0, "@".concat(config.name, " locations must be an Array."));
|
48 | var args = (_config$args = config.args) !== null && _config$args !== void 0 ? _config$args : {};
|
49 | isObjectLike(args) && !Array.isArray(args) || devAssert(0, "@".concat(config.name, " args must be an object with argument names as keys."));
|
50 | this.args = objectEntries(args).map(function (_ref) {
|
51 | var argName = _ref[0],
|
52 | argConfig = _ref[1];
|
53 | return {
|
54 | name: argName,
|
55 | description: argConfig.description,
|
56 | type: argConfig.type,
|
57 | defaultValue: argConfig.defaultValue,
|
58 | deprecationReason: argConfig.deprecationReason,
|
59 | extensions: argConfig.extensions && toObjMap(argConfig.extensions),
|
60 | astNode: argConfig.astNode
|
61 | };
|
62 | });
|
63 | }
|
64 |
|
65 | var _proto = GraphQLDirective.prototype;
|
66 |
|
67 | _proto.toConfig = function toConfig() {
|
68 | return {
|
69 | name: this.name,
|
70 | description: this.description,
|
71 | locations: this.locations,
|
72 | args: argsToArgsConfig(this.args),
|
73 | isRepeatable: this.isRepeatable,
|
74 | extensions: this.extensions,
|
75 | astNode: this.astNode
|
76 | };
|
77 | };
|
78 |
|
79 | _proto.toString = function toString() {
|
80 | return '@' + this.name;
|
81 | };
|
82 |
|
83 | _proto.toJSON = function toJSON() {
|
84 | return this.toString();
|
85 | }
|
86 | ;
|
87 |
|
88 | _createClass(GraphQLDirective, [{
|
89 | key: SYMBOL_TO_STRING_TAG,
|
90 | get: function get() {
|
91 | return 'GraphQLDirective';
|
92 | }
|
93 | }]);
|
94 |
|
95 | return GraphQLDirective;
|
96 | }();
|
97 |
|
98 | defineInspect(GraphQLDirective);
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | export var GraphQLIncludeDirective = new GraphQLDirective({
|
104 | name: 'include',
|
105 | description: 'Directs the executor to include this field or fragment only when the `if` argument is true.',
|
106 | locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
107 | args: {
|
108 | if: {
|
109 | type: new GraphQLNonNull(GraphQLBoolean),
|
110 | description: 'Included when true.'
|
111 | }
|
112 | }
|
113 | });
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | export var GraphQLSkipDirective = new GraphQLDirective({
|
119 | name: 'skip',
|
120 | description: 'Directs the executor to skip this field or fragment when the `if` argument is true.',
|
121 | locations: [DirectiveLocation.FIELD, DirectiveLocation.FRAGMENT_SPREAD, DirectiveLocation.INLINE_FRAGMENT],
|
122 | args: {
|
123 | if: {
|
124 | type: new GraphQLNonNull(GraphQLBoolean),
|
125 | description: 'Skipped when true.'
|
126 | }
|
127 | }
|
128 | });
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | export var DEFAULT_DEPRECATION_REASON = 'No longer supported';
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | export var GraphQLDeprecatedDirective = new GraphQLDirective({
|
139 | name: 'deprecated',
|
140 | description: 'Marks an element of a GraphQL schema as no longer supported.',
|
141 | locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.ARGUMENT_DEFINITION, DirectiveLocation.INPUT_FIELD_DEFINITION, DirectiveLocation.ENUM_VALUE],
|
142 | args: {
|
143 | reason: {
|
144 | type: GraphQLString,
|
145 | 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/).',
|
146 | defaultValue: DEFAULT_DEPRECATION_REASON
|
147 | }
|
148 | }
|
149 | });
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | export var GraphQLSpecifiedByDirective = new GraphQLDirective({
|
155 | name: 'specifiedBy',
|
156 | description: 'Exposes a URL that specifies the behaviour of this scalar.',
|
157 | locations: [DirectiveLocation.SCALAR],
|
158 | args: {
|
159 | url: {
|
160 | type: new GraphQLNonNull(GraphQLString),
|
161 | description: 'The URL that specifies the behaviour of this scalar.'
|
162 | }
|
163 | }
|
164 | });
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | export var specifiedDirectives = Object.freeze([GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective, GraphQLSpecifiedByDirective]);
|
170 | export function isSpecifiedDirective(directive) {
|
171 | return specifiedDirectives.some(function (_ref2) {
|
172 | var name = _ref2.name;
|
173 | return name === directive.name;
|
174 | });
|
175 | }
|