Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary concatenations from template strings #1957

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1046,19 +1046,16 @@ function ensureValidRuntimeType(

if (!isObjectType(runtimeType)) {
throw new GraphQLError(
`Abstract type ${returnType.name} must resolve to an Object type at ` +
`runtime for field ${info.parentType.name}.${info.fieldName} with ` +
`Abstract type ${returnType.name} must resolve to an Object type at runtime for field ${info.parentType.name}.${info.fieldName} with ` +
`value ${inspect(result)}, received "${inspect(runtimeType)}". ` +
`Either the ${returnType.name} type should provide a "resolveType" ` +
'function or each possible type should provide an "isTypeOf" function.',
`Either the ${returnType.name} type should provide a "resolveType" function or each possible type should provide an "isTypeOf" function.`,
fieldNodes,
);
}

if (!exeContext.schema.isPossibleType(returnType, runtimeType)) {
throw new GraphQLError(
`Runtime Object type "${runtimeType.name}" is not a possible type ` +
`for "${returnType.name}".`,
`Runtime Object type "${runtimeType.name}" is not a possible type for "${returnType.name}".`,
fieldNodes,
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/execution/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ export function getArgumentValues(
const variableName = argumentNode.value.name.value;
throw new GraphQLError(
`Argument "${name}" of required type "${inspect(argType)}" ` +
`was provided the variable "$${variableName}" ` +
'which was not provided a runtime value.',
`was provided the variable "$${variableName}" which was not provided a runtime value.`,
argumentNode.value,
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/language/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ function readString(source, start, line, col, prev): Token {
body.charCodeAt(position + 4),
);
if (charCode < 0) {
const invalidSequence = body.slice(position + 1, position + 5);
throw syntaxError(
source,
position,
'Invalid character escape sequence: ' +
`\\u${body.slice(position + 1, position + 5)}.`,
`Invalid character escape sequence: \\u${invalidSequence}.`,
);
}
value += String.fromCharCode(charCode);
Expand Down
30 changes: 10 additions & 20 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,14 @@ export class GraphQLScalarType {
invariant(typeof config.name === 'string', 'Must provide name.');
invariant(
config.serialize == null || typeof config.serialize === 'function',
`${this.name} must provide "serialize" function. If this custom Scalar ` +
'is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.',
`${this.name} must provide "serialize" function. If this custom Scalar is also used as an input type, ensure "parseValue" and "parseLiteral" functions are also provided.`,
);

if (config.parseLiteral) {
invariant(
typeof config.parseValue === 'function' &&
typeof config.parseLiteral === 'function',
`${this.name} must provide both "parseValue" and "parseLiteral" ` +
'functions.',
`${this.name} must provide both "parseValue" and "parseLiteral" functions.`,
);
}
}
Expand Down Expand Up @@ -740,8 +738,7 @@ function defineInterfaces(
const interfaces = resolveThunk(config.interfaces) || [];
invariant(
Array.isArray(interfaces),
`${config.name} interfaces must be an Array or a function which returns ` +
'an Array.',
`${config.name} interfaces must be an Array or a function which returns an Array.`,
);
return interfaces;
}
Expand All @@ -754,8 +751,7 @@ function defineFieldMap<TSource, TContext>(
const fieldMap = resolveThunk(config.fields) || {};
invariant(
isPlainObj(fieldMap),
`${config.name} fields must be an object with field names as keys or a ` +
'function which returns such an object.',
`${config.name} fields must be an object with field names as keys or a function which returns such an object.`,
);

return mapValue(fieldMap, (fieldConfig, fieldName) => {
Expand All @@ -765,8 +761,7 @@ function defineFieldMap<TSource, TContext>(
);
invariant(
!('isDeprecated' in fieldConfig),
`${config.name}.${fieldName} should provide "deprecationReason" ` +
'instead of "isDeprecated".',
`${config.name}.${fieldName} should provide "deprecationReason" instead of "isDeprecated".`,
);
invariant(
fieldConfig.resolve == null || typeof fieldConfig.resolve === 'function',
Expand All @@ -777,8 +772,7 @@ function defineFieldMap<TSource, TContext>(
const argsConfig = fieldConfig.args || {};
invariant(
isPlainObj(argsConfig),
`${config.name}.${fieldName} args must be an object with argument ` +
'names as keys.',
`${config.name}.${fieldName} args must be an object with argument names as keys.`,
);

const args = objectEntries(argsConfig).map(([argName, arg]) => ({
Expand Down Expand Up @@ -1111,8 +1105,7 @@ function defineTypes(
const types = resolveThunk(config.types) || [];
invariant(
Array.isArray(types),
'Must provide Array of types or a function which returns ' +
`such an array for Union ${config.name}.`,
`Must provide Array of types or a function which returns such an array for Union ${config.name}.`,
);
return types;
}
Expand Down Expand Up @@ -1259,8 +1252,7 @@ function defineEnumValues(
);
invariant(
!('isDeprecated' in value),
`${type.name}.${valueName} should provide "deprecationReason" instead ` +
'of "isDeprecated".',
`${type.name}.${valueName} should provide "deprecationReason" instead of "isDeprecated".`,
);
return {
name: valueName,
Expand Down Expand Up @@ -1379,14 +1371,12 @@ function defineInputFieldMap(
const fieldMap = resolveThunk(config.fields) || {};
invariant(
isPlainObj(fieldMap),
`${config.name} fields must be an object with field names as keys or a ` +
'function which returns such an object.',
`${config.name} fields must be an object with field names as keys or a function which returns such an object.`,
);
return mapValue(fieldMap, (fieldConfig, fieldName) => {
invariant(
!('resolve' in fieldConfig),
`${config.name}.${fieldName} field has a resolve property, but ` +
'Input Types cannot define resolvers.',
`${config.name}.${fieldName} field has a resolve property, but Input Types cannot define resolvers.`,
);

return { ...fieldConfig, name: fieldName };
Expand Down
21 changes: 7 additions & 14 deletions src/type/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ function validateFields(
// Ensure they are unique per field.
if (argNames[argName]) {
context.reportError(
`Field argument ${type.name}.${field.name}(${argName}:) can only ` +
'be defined once.',
`Field argument ${type.name}.${field.name}(${argName}:) can only be defined once.`,
field.args
.filter(({ name }) => name === argName)
.map(({ astNode }) => astNode),
Expand Down Expand Up @@ -364,8 +363,7 @@ function validateObjectImplementsInterface(
// Assert interface field exists on object.
if (!objectField) {
context.reportError(
`Interface field ${iface.name}.${fieldName} expected but ` +
`${object.name} does not provide it.`,
`Interface field ${iface.name}.${fieldName} expected but ${object.name} does not provide it.`,
[ifaceField.astNode, ...getAllNodes(object)],
);
continue;
Expand Down Expand Up @@ -393,8 +391,7 @@ function validateObjectImplementsInterface(
// Assert interface field arg exists on object field.
if (!objectArg) {
context.reportError(
`Interface field argument ${iface.name}.${fieldName}(${argName}:) ` +
`expected but ${object.name}.${fieldName} does not provide it.`,
`Interface field argument ${iface.name}.${fieldName}(${argName}:) expected but ${object.name}.${fieldName} does not provide it.`,
[ifaceArg.astNode, objectField.astNode],
);
continue;
Expand Down Expand Up @@ -425,9 +422,7 @@ function validateObjectImplementsInterface(
const ifaceArg = find(ifaceField.args, arg => arg.name === argName);
if (!ifaceArg && isRequiredArgument(objectArg)) {
context.reportError(
`Object field ${object.name}.${fieldName} includes required ` +
`argument ${argName} that is missing from the Interface field ` +
`${iface.name}.${fieldName}.`,
`Object field ${object.name}.${fieldName} includes required argument ${argName} that is missing from the Interface field ${iface.name}.${fieldName}.`,
[objectArg.astNode, ifaceField.astNode],
);
}
Expand All @@ -452,8 +447,7 @@ function validateUnionMembers(
for (const memberType of memberTypes) {
if (includedTypeNames[memberType.name]) {
context.reportError(
`Union type ${union.name} can only include type ` +
`${memberType.name} once.`,
`Union type ${union.name} can only include type ${memberType.name} once.`,
getUnionMemberTypeNodes(union, memberType.name),
);
continue;
Expand Down Expand Up @@ -563,10 +557,9 @@ function createInputObjectCircularRefsValidator(
detectCycleRecursive(fieldType);
} else {
const cyclePath = fieldPath.slice(cycleIndex);
const fieldNames = cyclePath.map(fieldObj => fieldObj.name);
const pathStr = cyclePath.map(fieldObj => fieldObj.name).join('.');
context.reportError(
`Cannot reference Input Object "${fieldType.name}" within itself ` +
`through a series of non-null fields: "${fieldNames.join('.')}".`,
`Cannot reference Input Object "${fieldType.name}" within itself through a series of non-null fields: "${pathStr}".`,
cyclePath.map(fieldObj => fieldObj.astNode),
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/assertValidName.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export function isValidNameError(
invariant(typeof name === 'string', 'Expected string');
if (name.length > 1 && name[0] === '_' && name[1] === '_') {
return new GraphQLError(
`Name "${name}" must not begin with "__", which is reserved by ` +
'GraphQL introspection.',
`Name "${name}" must not begin with "__", which is reserved by GraphQL introspection.`,
node,
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ export function buildClientSchema(
const type = typeMap[typeName];
if (!type) {
throw new Error(
`Invalid or incomplete schema, unknown type: ${typeName}. Ensure ` +
'that a full introspection query is used in order to build a client schema.',
`Invalid or incomplete schema, unknown type: ${typeName}. Ensure that a full introspection query is used in order to build a client schema.`,
);
}

Expand Down
44 changes: 11 additions & 33 deletions src/utilities/findBreakingChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ function findDirectiveChanges(
if (isRequiredArgument(newArg)) {
schemaChanges.push({
type: BreakingChangeType.REQUIRED_DIRECTIVE_ARG_ADDED,
description:
`A required arg ${newArg.name} on directive ` +
`${oldDirective.name} was added.`,
description: `A required arg ${newArg.name} on directive ${oldDirective.name} was added.`,
});
}
}
Expand Down Expand Up @@ -220,16 +218,12 @@ function findInputObjectTypeChanges(
if (isRequiredInputField(newField)) {
schemaChanges.push({
type: BreakingChangeType.REQUIRED_INPUT_FIELD_ADDED,
description:
`A required field ${newField.name} on ` +
`input type ${oldType.name} was added.`,
description: `A required field ${newField.name} on input type ${oldType.name} was added.`,
});
} else {
schemaChanges.push({
type: DangerousChangeType.OPTIONAL_INPUT_FIELD_ADDED,
description:
`An optional field ${newField.name} on ` +
`input type ${oldType.name} was added.`,
description: `An optional field ${newField.name} on input type ${oldType.name} was added.`,
});
}
}
Expand Down Expand Up @@ -276,9 +270,7 @@ function findUnionTypeChanges(
for (const oldPossibleType of possibleTypesDiff.removed) {
schemaChanges.push({
type: BreakingChangeType.TYPE_REMOVED_FROM_UNION,
description:
`${oldPossibleType.name} was removed from ` +
`union type ${oldType.name}.`,
description: `${oldPossibleType.name} was removed from union type ${oldType.name}.`,
});
}

Expand Down Expand Up @@ -319,18 +311,14 @@ function findObjectTypeChanges(
for (const newInterface of interfacesDiff.added) {
schemaChanges.push({
type: DangerousChangeType.INTERFACE_ADDED_TO_OBJECT,
description:
`${newInterface.name} added to interfaces implemented ` +
`by ${oldType.name}.`,
description: `${newInterface.name} added to interfaces implemented by ${oldType.name}.`,
});
}

for (const oldInterface of interfacesDiff.removed) {
schemaChanges.push({
type: BreakingChangeType.INTERFACE_REMOVED_FROM_OBJECT,
description:
`${oldType.name} no longer implements interface ` +
`${oldInterface.name}.`,
description: `${oldType.name} no longer implements interface ${oldInterface.name}.`,
});
}

Expand Down Expand Up @@ -398,17 +386,14 @@ function findArgChanges(
schemaChanges.push({
type: BreakingChangeType.ARG_CHANGED_KIND,
description:
`${oldType.name}.${oldField.name} arg ` +
`${oldArg.name} has changed type from ` +
`${oldType.name}.${oldField.name} arg ${oldArg.name} has changed type from ` +
`${String(oldArg.type)} to ${String(newArg.type)}.`,
});
} else if (oldArg.defaultValue !== undefined) {
if (newArg.defaultValue === undefined) {
schemaChanges.push({
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
description:
`${oldType.name}.${oldField.name} arg ` +
`${oldArg.name} defaultValue was removed.`,
description: `${oldType.name}.${oldField.name} arg ${oldArg.name} defaultValue was removed.`,
});
} else {
const oldValueStr = stringifyValue(oldArg.defaultValue, oldArg.type);
Expand All @@ -417,10 +402,7 @@ function findArgChanges(
if (oldValueStr !== newValueStr) {
schemaChanges.push({
type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
description:
`${oldType.name}.${oldField.name} arg ` +
`${oldArg.name} has changed defaultValue ` +
`from ${oldValueStr} to ${newValueStr}.`,
description: `${oldType.name}.${oldField.name} arg ${oldArg.name} has changed defaultValue from ${oldValueStr} to ${newValueStr}.`,
});
}
}
Expand All @@ -431,16 +413,12 @@ function findArgChanges(
if (isRequiredArgument(newArg)) {
schemaChanges.push({
type: BreakingChangeType.REQUIRED_ARG_ADDED,
description:
`A required arg ${newArg.name} on ` +
`${oldType.name}.${oldField.name} was added.`,
description: `A required arg ${newArg.name} on ${oldType.name}.${oldField.name} was added.`,
});
} else {
schemaChanges.push({
type: DangerousChangeType.OPTIONAL_ARG_ADDED,
description:
`An optional arg ${newArg.name} on ` +
`${oldType.name}.${oldField.name} was added.`,
description: `An optional arg ${newArg.name} on ${oldType.name}.${oldField.name} was added.`,
});
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/validation/rules/FragmentsOnCompositeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ export function fragmentOnNonCompositeErrorMessage(
fragName: string,
type: string,
): string {
return (
`Fragment "${fragName}" cannot condition on non composite ` +
`type "${type}".`
);
return `Fragment "${fragName}" cannot condition on non composite type "${type}".`;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/validation/rules/PossibleFragmentSpreads.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ export function typeIncompatibleSpreadMessage(
parentType: string,
fragType: string,
): string {
return (
`Fragment "${fragName}" cannot be spread here as objects of ` +
`type "${parentType}" can never be of type "${fragType}".`
);
return `Fragment "${fragName}" cannot be spread here as objects of type "${parentType}" can never be of type "${fragType}".`;
}

export function typeIncompatibleAnonSpreadMessage(
parentType: string,
fragType: string,
): string {
return (
'Fragment cannot be spread here as objects of ' +
`type "${parentType}" can never be of type "${fragType}".`
);
return `Fragment cannot be spread here as objects of type "${parentType}" can never be of type "${fragType}".`;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/validation/rules/ProvidedRequiredArguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ export function missingFieldArgMessage(
argName: string,
type: string,
): string {
return (
`Field "${fieldName}" argument "${argName}" of type ` +
`"${type}" is required, but it was not provided.`
);
return `Field "${fieldName}" argument "${argName}" of type "${type}" is required, but it was not provided.`;
}

export function missingDirectiveArgMessage(
directiveName: string,
argName: string,
type: string,
): string {
return (
`Directive "@${directiveName}" argument "${argName}" of type ` +
`"${type}" is required, but it was not provided.`
);
return `Directive "@${directiveName}" argument "${argName}" of type "${type}" is required, but it was not provided.`;
}

/**
Expand Down
Loading