UNPKG

949 BJavaScriptView Raw
1import { devAssert } from '../jsutils/devAssert.mjs';
2import { GraphQLError } from '../error/GraphQLError.mjs';
3import { assertName } from '../type/assertName.mjs';
4/* c8 ignore start */
5
6/**
7 * Upholds the spec rules about naming.
8 * @deprecated Please use `assertName` instead. Will be removed in v17
9 */
10
11export function assertValidName(name) {
12 const error = isValidNameError(name);
13
14 if (error) {
15 throw error;
16 }
17
18 return name;
19}
20/**
21 * Returns an Error if a name is invalid.
22 * @deprecated Please use `assertName` instead. Will be removed in v17
23 */
24
25export function isValidNameError(name) {
26 typeof name === 'string' || devAssert(false, 'Expected name to be a string.');
27
28 if (name.startsWith('__')) {
29 return new GraphQLError(
30 `Name "${name}" must not begin with "__", which is reserved by GraphQL introspection.`,
31 );
32 }
33
34 try {
35 assertName(name);
36 } catch (error) {
37 return error;
38 }
39}
40/* c8 ignore stop */