import { devAssert } from '../jsutils/devAssert';
import { GraphQLError } from '../error/GraphQLError';
import { assertName } from '../type/assertName';
export function assertValidName(name: string): string {
const error = isValidNameError(name);
if (error) {
throw error;
}
return name;
}
export function isValidNameError(name: string): GraphQLError | undefined {
devAssert(typeof name === 'string', 'Expected name to be a string.');
if (name.startsWith('__')) {
return new GraphQLError(
`Name "${name}" must not begin with "__", which is reserved by GraphQL introspection.`,
);
}
try {
assertName(name);
} catch (error) {
return error;
}
}