1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true,
|
5 | });
|
6 | exports.assertValidName = assertValidName;
|
7 | exports.isValidNameError = isValidNameError;
|
8 |
|
9 | var _devAssert = require('../jsutils/devAssert.js');
|
10 |
|
11 | var _GraphQLError = require('../error/GraphQLError.js');
|
12 |
|
13 | var _assertName = require('../type/assertName.js');
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | function assertValidName(name) {
|
22 | const error = isValidNameError(name);
|
23 |
|
24 | if (error) {
|
25 | throw error;
|
26 | }
|
27 |
|
28 | return name;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function isValidNameError(name) {
|
36 | typeof name === 'string' ||
|
37 | (0, _devAssert.devAssert)(false, 'Expected name to be a string.');
|
38 |
|
39 | if (name.startsWith('__')) {
|
40 | return new _GraphQLError.GraphQLError(
|
41 | `Name "${name}" must not begin with "__", which is reserved by GraphQL introspection.`,
|
42 | );
|
43 | }
|
44 |
|
45 | try {
|
46 | (0, _assertName.assertName)(name);
|
47 | } catch (error) {
|
48 | return error;
|
49 | }
|
50 | }
|
51 |
|