Skip to content

Fix bunch of edge cases with empty strings #2178

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

Merged
merged 1 commit into from
Sep 17, 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
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

[lints]
sketchy-null-bool=off
sketchy-null-string=off
sketchy-null-string=error
sketchy-null-number=error
sketchy-null-mixed=error
sketchy-number=error
Expand Down
4 changes: 3 additions & 1 deletion src/jsutils/invariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
export default function invariant(condition: mixed, message?: string): void {
const booleanCondition = Boolean(condition);
if (!booleanCondition) {
throw new Error(message || 'Unexpected invariant triggered');
throw new Error(
message != null ? message : 'Unexpected invariant triggered',
);
}
}
2 changes: 1 addition & 1 deletion src/language/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Source {

constructor(body: string, name?: string, locationOffset?: Location): void {
this.body = body;
this.name = name || 'GraphQL request';
this.name = name != null ? name : 'GraphQL request';
this.locationOffset = locationOffset || { line: 1, column: 1 };
devAssert(
this.locationOffset.line > 0,
Expand Down
7 changes: 4 additions & 3 deletions src/utilities/buildClientSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ export function buildClientSchema(

function buildInputValue(inputValueIntrospection) {
const type = getInputType(inputValueIntrospection.type);
const defaultValue = inputValueIntrospection.defaultValue
? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type)
: undefined;
const defaultValue =
inputValueIntrospection.defaultValue != null
? valueFromAST(parseValue(inputValueIntrospection.defaultValue), type)
: undefined;
return {
description: inputValueIntrospection.description,
type,
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function extendSchema(
}

function getMaybeTypeByName(typeName: ?string): ?GraphQLNamedType {
return typeName ? typeMap[typeName] : null;
return typeName != null ? typeMap[typeName] : null;
}

function getMergedDirectives(): Array<GraphQLDirective> {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/findDeprecatedUsages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function findDeprecatedUsages(
errors.push(
new GraphQLError(
`The field "${parentType.name}.${fieldDef.name}" is deprecated.` +
(reason ? ' ' + reason : ''),
(reason != null ? ' ' + reason : ''),
node,
),
);
Expand All @@ -50,7 +50,7 @@ export function findDeprecatedUsages(
errors.push(
new GraphQLError(
`The enum value "${type.name}.${enumVal.name}" is deprecated.` +
(reason ? ' ' + reason : ''),
(reason != null && reason !== '' ? ' ' + reason : ''),
node,
),
);
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/getOperationAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getOperationAST(
let operation = null;
for (const definition of documentAST.definitions) {
if (definition.kind === Kind.OPERATION_DEFINITION) {
if (!operationName) {
if (operationName == null) {
// If no operation name was provided, only return an Operation if there
// is one defined in the document. Upon encountering the second, return
// null.
Expand Down