MCPcopy
hub / github.com/graphql/graphql-js / assertName

Function assertName

src/type/assertName.ts:19–39  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

17 * ```
18 */
19export function assertName(name: string): string {
20 if (name.length === 0) {
21 throw new GraphQLError('Expected name to be a non-empty string.');
22 }
23
24 for (let i = 1; i < name.length; ++i) {
25 if (!isNameContinue(name.charCodeAt(i))) {
26 throw new GraphQLError(
27 `Names must only contain [_a-zA-Z0-9] but "${name}" does not.`,
28 );
29 }
30 }
31
32 if (!isNameStart(name.charCodeAt(0))) {
33 throw new GraphQLError(
34 `Names must start with [_a-zA-Z] but "${name}" does not.`,
35 );
36 }
37
38 return name;
39}
40
41/**
42 * Upholds the spec rules about naming enum values.

Callers 12

constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90
assertName-test.tsFile · 0.90
assertEnumValueNameFunction · 0.85

Calls 2

isNameContinueFunction · 0.90
isNameStartFunction · 0.90

Tested by

no test coverage detected