1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.assertValidName = assertValidName;
|
7 | exports.isValidNameError = isValidNameError;
|
8 |
|
9 | var _GraphQLError = require('../error/GraphQLError');
|
10 |
|
11 | var _invariant = require('../jsutils/invariant');
|
12 |
|
13 | var _invariant2 = _interopRequireDefault(_invariant);
|
14 |
|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | var NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function assertValidName(name) {
|
32 | var error = isValidNameError(name);
|
33 | if (error) {
|
34 | throw error;
|
35 | }
|
36 | return name;
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | function isValidNameError(name, node) {
|
43 | !(typeof name === 'string') ? (0, _invariant2.default)(0, 'Expected string') : void 0;
|
44 | if (name.length > 1 && name[0] === '_' && name[1] === '_' &&
|
45 |
|
46 |
|
47 |
|
48 | name !== '__configs__') {
|
49 | return new _GraphQLError.GraphQLError('Name "' + name + '" must not begin with "__", which is reserved by ' + 'GraphQL introspection.', node);
|
50 | }
|
51 | if (!NAME_RX.test(name)) {
|
52 | return new _GraphQLError.GraphQLError('Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "' + name + '" does not.', node);
|
53 | }
|
54 | } |
\ | No newline at end of file |