Skip to content

Commit d9cc4b9

Browse files
Fix bunch of edge cases with empty strings (#2178)
1 parent 2e1becb commit d9cc4b9

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

Diff for: .flowconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
[lints]
1313
sketchy-null-bool=off
14-
sketchy-null-string=off
14+
sketchy-null-string=error
1515
sketchy-null-number=error
1616
sketchy-null-mixed=error
1717
sketchy-number=error

Diff for: src/jsutils/invariant.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
export default function invariant(condition: mixed, message?: string): void {
44
const booleanCondition = Boolean(condition);
55
if (!booleanCondition) {
6-
throw new Error(message || 'Unexpected invariant triggered');
6+
throw new Error(
7+
message != null ? message : 'Unexpected invariant triggered',
8+
);
79
}
810
}

Diff for: src/language/source.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class Source {
2323

2424
constructor(body: string, name?: string, locationOffset?: Location): void {
2525
this.body = body;
26-
this.name = name || 'GraphQL request';
26+
this.name = name != null ? name : 'GraphQL request';
2727
this.locationOffset = locationOffset || { line: 1, column: 1 };
2828
devAssert(
2929
this.locationOffset.line > 0,

Diff for: src/utilities/buildClientSchema.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ export function buildClientSchema(
350350

351351
function buildInputValue(inputValueIntrospection) {
352352
const type = getInputType(inputValueIntrospection.type);
353-
const defaultValue = inputValueIntrospection.defaultValue
354-
? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type)
355-
: undefined;
353+
const defaultValue =
354+
inputValueIntrospection.defaultValue != null
355+
? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type)
356+
: undefined;
356357
return {
357358
description: inputValueIntrospection.description,
358359
type,

Diff for: src/utilities/extendSchema.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export function extendSchema(
222222
}
223223

224224
function getMaybeTypeByName(typeName: ?string): ?GraphQLNamedType {
225-
return typeName ? typeMap[typeName] : null;
225+
return typeName != null ? typeMap[typeName] : null;
226226
}
227227

228228
function getMergedDirectives(): Array<GraphQLDirective> {

Diff for: src/utilities/findDeprecatedUsages.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function findDeprecatedUsages(
3434
errors.push(
3535
new GraphQLError(
3636
`The field "${parentType.name}.${fieldDef.name}" is deprecated.` +
37-
(reason ? ' ' + reason : ''),
37+
(reason != null ? ' ' + reason : ''),
3838
node,
3939
),
4040
);
@@ -50,7 +50,7 @@ export function findDeprecatedUsages(
5050
errors.push(
5151
new GraphQLError(
5252
`The enum value "${type.name}.${enumVal.name}" is deprecated.` +
53-
(reason ? ' ' + reason : ''),
53+
(reason != null && reason !== '' ? ' ' + reason : ''),
5454
node,
5555
),
5656
);

Diff for: src/utilities/getOperationAST.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function getOperationAST(
1818
let operation = null;
1919
for (const definition of documentAST.definitions) {
2020
if (definition.kind === Kind.OPERATION_DEFINITION) {
21-
if (!operationName) {
21+
if (operationName == null) {
2222
// If no operation name was provided, only return an Operation if there
2323
// is one defined in the document. Upon encountering the second, return
2424
// null.

0 commit comments

Comments
 (0)