UNPKG

1.16 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true,
5});
6exports.assertValidName = assertValidName;
7exports.isValidNameError = isValidNameError;
8
9var _devAssert = require('../jsutils/devAssert.js');
10
11var _GraphQLError = require('../error/GraphQLError.js');
12
13var _assertName = require('../type/assertName.js');
14
15/* c8 ignore start */
16
17/**
18 * Upholds the spec rules about naming.
19 * @deprecated Please use `assertName` instead. Will be removed in v17
20 */
21function assertValidName(name) {
22 const error = isValidNameError(name);
23
24 if (error) {
25 throw error;
26 }
27
28 return name;
29}
30/**
31 * Returns an Error if a name is invalid.
32 * @deprecated Please use `assertName` instead. Will be removed in v17
33 */
34
35function 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/* c8 ignore stop */