1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.specifiedDirectives = exports.GraphQLDeprecatedDirective = exports.DEFAULT_DEPRECATION_REASON = exports.GraphQLSkipDirective = exports.GraphQLIncludeDirective = exports.GraphQLDirective = undefined;
|
7 | exports.isDirective = isDirective;
|
8 | exports.isSpecifiedDirective = isSpecifiedDirective;
|
9 |
|
10 | var _wrappers = require('./wrappers');
|
11 |
|
12 | var _scalars = require('./scalars');
|
13 |
|
14 | var _instanceOf = require('../jsutils/instanceOf');
|
15 |
|
16 | var _instanceOf2 = _interopRequireDefault(_instanceOf);
|
17 |
|
18 | var _invariant = require('../jsutils/invariant');
|
19 |
|
20 | var _invariant2 = _interopRequireDefault(_invariant);
|
21 |
|
22 | var _directiveLocation = require('../language/directiveLocation');
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function isDirective(directive) {
|
42 | return (0, _instanceOf2.default)(directive, GraphQLDirective);
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | var GraphQLDirective = exports.GraphQLDirective = function GraphQLDirective(config) {
|
51 | _classCallCheck(this, GraphQLDirective);
|
52 |
|
53 | this.name = config.name;
|
54 | this.description = config.description;
|
55 | this.locations = config.locations;
|
56 | this.astNode = config.astNode;
|
57 | !config.name ? (0, _invariant2.default)(0, 'Directive must be named.') : void 0;
|
58 | !Array.isArray(config.locations) ? (0, _invariant2.default)(0, 'Must provide locations for directive.') : void 0;
|
59 |
|
60 | var args = config.args;
|
61 | if (!args) {
|
62 | this.args = [];
|
63 | } else {
|
64 | !!Array.isArray(args) ? (0, _invariant2.default)(0, '@' + config.name + ' args must be an object with argument names as keys.') : void 0;
|
65 | this.args = Object.keys(args).map(function (argName) {
|
66 | var arg = args[argName];
|
67 | return {
|
68 | name: argName,
|
69 | description: arg.description === undefined ? null : arg.description,
|
70 | type: arg.type,
|
71 | defaultValue: arg.defaultValue,
|
72 | astNode: arg.astNode
|
73 | };
|
74 | });
|
75 | }
|
76 | };
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var GraphQLIncludeDirective = exports.GraphQLIncludeDirective = new GraphQLDirective({
|
82 | name: 'include',
|
83 | description: 'Directs the executor to include this field or fragment only when ' + 'the `if` argument is true.',
|
84 | locations: [_directiveLocation.DirectiveLocation.FIELD, _directiveLocation.DirectiveLocation.FRAGMENT_SPREAD, _directiveLocation.DirectiveLocation.INLINE_FRAGMENT],
|
85 | args: {
|
86 | if: {
|
87 | type: (0, _wrappers.GraphQLNonNull)(_scalars.GraphQLBoolean),
|
88 | description: 'Included when true.'
|
89 | }
|
90 | }
|
91 | });
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | var GraphQLSkipDirective = exports.GraphQLSkipDirective = new GraphQLDirective({
|
97 | name: 'skip',
|
98 | description: 'Directs the executor to skip this field or fragment when the `if` ' + 'argument is true.',
|
99 | locations: [_directiveLocation.DirectiveLocation.FIELD, _directiveLocation.DirectiveLocation.FRAGMENT_SPREAD, _directiveLocation.DirectiveLocation.INLINE_FRAGMENT],
|
100 | args: {
|
101 | if: {
|
102 | type: (0, _wrappers.GraphQLNonNull)(_scalars.GraphQLBoolean),
|
103 | description: 'Skipped when true.'
|
104 | }
|
105 | }
|
106 | });
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | var DEFAULT_DEPRECATION_REASON = exports.DEFAULT_DEPRECATION_REASON = 'No longer supported';
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | var GraphQLDeprecatedDirective = exports.GraphQLDeprecatedDirective = new GraphQLDirective({
|
117 | name: 'deprecated',
|
118 | description: 'Marks an element of a GraphQL schema as no longer supported.',
|
119 | locations: [_directiveLocation.DirectiveLocation.FIELD_DEFINITION, _directiveLocation.DirectiveLocation.ENUM_VALUE],
|
120 | args: {
|
121 | reason: {
|
122 | type: _scalars.GraphQLString,
|
123 | description: 'Explains why this element was deprecated, usually also including a ' + 'suggestion for how to access supported similar data. Formatted ' + 'in [Markdown](https://daringfireball.net/projects/markdown/).',
|
124 | defaultValue: DEFAULT_DEPRECATION_REASON
|
125 | }
|
126 | }
|
127 | });
|
128 |
|
129 |
|
130 |
|
131 |
|
132 | var specifiedDirectives = exports.specifiedDirectives = [GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective];
|
133 |
|
134 | function isSpecifiedDirective(directive) {
|
135 | return specifiedDirectives.some(function (specifiedDirective) {
|
136 | return specifiedDirective.name === directive.name;
|
137 | });
|
138 | } |
\ | No newline at end of file |