1 | import { devAssert } from '../jsutils/devAssert.mjs';
|
2 | import { GraphQLError } from '../error/GraphQLError.mjs';
|
3 | import { assertName } from '../type/assertName.mjs';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function assertValidName(name) {
|
12 | const error = isValidNameError(name);
|
13 |
|
14 | if (error) {
|
15 | throw error;
|
16 | }
|
17 |
|
18 | return name;
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export 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 |
|