importdevAssertfrom'../jsutils/devAssert';import{GraphQLError}from'../error/GraphQLError';varNAME_RX=/^[_a-zA-Z][_a-zA-Z0-9]*$/;/** * Upholds the spec rules about naming. */exportfunctionassertValidName(name){varerror=isValidNameError(name);if(error){throwerror;}returnname;}/** * Returns an Error if a name is invalid. */exportfunctionisValidNameError(name,node){typeofname==='string'||devAssert(0,'Expected string');if(name.length>1&&name[0]==='_'&&name[1]==='_'){returnnewGraphQLError("Name \"".concat(name,"\" must not begin with \"__\", which is reserved by GraphQL introspection."),node);}if(!NAME_RX.test(name)){returnnewGraphQLError("Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but \"".concat(name,"\" does not."),node);}}