From 611d17b052a6a9d0d75ace8c5ef9d9552a76778c Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Mon, 3 Feb 2020 13:03:30 +0800 Subject: [PATCH] Use nullish coalescing operator in all appropriate places --- src/__tests__/starWarsData.js | 2 +- src/error/GraphQLError.js | 12 +++---- src/error/formatError.js | 2 +- src/error/locatedError.js | 2 +- src/execution/execute.js | 12 +++---- src/execution/values.js | 2 +- src/language/lexer.js | 2 +- src/language/parser.js | 2 +- src/language/printer.js | 2 +- src/language/visitor.js | 2 +- src/subscription/subscribe.js | 2 +- src/type/definition.js | 10 +++--- src/type/directives.js | 4 +-- src/type/schema.js | 4 +-- src/type/validate.js | 6 ++-- src/utilities/TypeInfo.js | 4 +-- .../__tests__/buildASTSchema-test.js | 20 +++++++++-- .../__tests__/stripIgnoredCharacters-test.js | 2 +- src/utilities/buildASTSchema.js | 15 ++++---- src/utilities/extendSchema.js | 36 +++++++++---------- .../rules/FieldsOnCorrectTypeRule.js | 2 +- .../rules/KnownArgumentNamesRule.js | 2 +- src/validation/rules/KnownTypeNamesRule.js | 2 +- .../rules/LoneSchemaDefinitionRule.js | 6 ++-- .../rules/OverlappingFieldsCanBeMergedRule.js | 4 +-- .../rules/ProvidedRequiredArgumentsRule.js | 6 ++-- .../rules/UniqueEnumValueNamesRule.js | 2 +- .../rules/UniqueFieldDefinitionNamesRule.js | 2 +- .../rules/UniqueOperationTypesRule.js | 2 +- 29 files changed, 93 insertions(+), 78 deletions(-) diff --git a/src/__tests__/starWarsData.js b/src/__tests__/starWarsData.js index e516fd7b59..087af78aa2 100644 --- a/src/__tests__/starWarsData.js +++ b/src/__tests__/starWarsData.js @@ -117,7 +117,7 @@ export type Droid = {| */ function getCharacter(id) { // Returning a promise just to illustrate that GraphQL.js supports it. - return Promise.resolve(humanData[id] || droidData[id]); + return Promise.resolve(humanData[id] ?? droidData[id]); } /** diff --git a/src/error/GraphQLError.js b/src/error/GraphQLError.js index a37aeaeea8..b847f42613 100644 --- a/src/error/GraphQLError.js +++ b/src/error/GraphQLError.js @@ -148,7 +148,7 @@ export class GraphQLError extends Error { locations: { // Coercing falsy values to undefined ensures they will not be included // in JSON.stringify() when not provided. - value: _locations || undefined, + value: _locations ?? undefined, // By being enumerable, JSON.stringify will include `locations` in the // resulting output. This ensures that the simplest possible GraphQL // service adheres to the spec. @@ -157,20 +157,20 @@ export class GraphQLError extends Error { path: { // Coercing falsy values to undefined ensures they will not be included // in JSON.stringify() when not provided. - value: path || undefined, + value: path ?? undefined, // By being enumerable, JSON.stringify will include `path` in the // resulting output. This ensures that the simplest possible GraphQL // service adheres to the spec. enumerable: path != null, }, nodes: { - value: _nodes || undefined, + value: _nodes ?? undefined, }, source: { - value: _source || undefined, + value: _source ?? undefined, }, positions: { - value: _positions || undefined, + value: _positions ?? undefined, }, originalError: { value: originalError, @@ -178,7 +178,7 @@ export class GraphQLError extends Error { extensions: { // Coercing falsy values to undefined ensures they will not be included // in JSON.stringify() when not provided. - value: _extensions || undefined, + value: _extensions ?? undefined, // By being enumerable, JSON.stringify will include `path` in the // resulting output. This ensures that the simplest possible GraphQL // service adheres to the spec. diff --git a/src/error/formatError.js b/src/error/formatError.js index a3616e8a67..8bb4c5b8f6 100644 --- a/src/error/formatError.js +++ b/src/error/formatError.js @@ -12,7 +12,7 @@ import { type GraphQLError } from './GraphQLError'; */ export function formatError(error: GraphQLError): GraphQLFormattedError { devAssert(error, 'Received null or undefined error.'); - const message = error.message || 'An unknown error occurred.'; + const message = error.message ?? 'An unknown error occurred.'; const locations = error.locations; const path = error.path; const extensions = error.extensions; diff --git a/src/error/locatedError.js b/src/error/locatedError.js index bb273332fe..01b6fe7ea3 100644 --- a/src/error/locatedError.js +++ b/src/error/locatedError.js @@ -22,7 +22,7 @@ export function locatedError( return new GraphQLError( originalError.message, - (originalError: any).nodes || nodes, + (originalError: any).nodes ?? nodes, (originalError: any).source, (originalError: any).positions, path, diff --git a/src/execution/execute.js b/src/execution/execute.js index adec10af28..97fba4cd71 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -314,12 +314,12 @@ export function buildExecutionContext( } /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const variableDefinitions = operation.variableDefinitions || []; + const variableDefinitions = operation.variableDefinitions ?? []; const coercedVariableValues = getVariableValues( schema, variableDefinitions, - rawVariableValues || {}, + rawVariableValues ?? {}, { maxErrors: 50 }, ); @@ -334,8 +334,8 @@ export function buildExecutionContext( contextValue, operation, variableValues: coercedVariableValues.coerced, - fieldResolver: fieldResolver || defaultFieldResolver, - typeResolver: typeResolver || defaultTypeResolver, + fieldResolver: fieldResolver ?? defaultFieldResolver, + typeResolver: typeResolver ?? defaultTypeResolver, errors: [], }; } @@ -619,7 +619,7 @@ function resolveField( return; } - const resolveFn = fieldDef.resolve || exeContext.fieldResolver; + const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver; const info = buildResolveInfo( exeContext, @@ -961,7 +961,7 @@ function completeAbstractValue( path: Path, result: mixed, ): PromiseOrValue> { - const resolveTypeFn = returnType.resolveType || exeContext.typeResolver; + const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver; const contextValue = exeContext.contextValue; const runtimeType = resolveTypeFn(result, contextValue, info, returnType); diff --git a/src/execution/values.js b/src/execution/values.js index 8496537d9e..44c514967a 100644 --- a/src/execution/values.js +++ b/src/execution/values.js @@ -166,7 +166,7 @@ export function getArgumentValues( const coercedValues = {}; /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argumentNodes = node.arguments || []; + const argumentNodes = node.arguments ?? []; const argNodeMap = keyMap(argumentNodes, arg => arg.name.value); for (const argDef of def.args) { diff --git a/src/language/lexer.js b/src/language/lexer.js index 58e3a0d419..b6ab501308 100644 --- a/src/language/lexer.js +++ b/src/language/lexer.js @@ -66,7 +66,7 @@ export class Lexer { if (token.kind !== TokenKind.EOF) { do { // Note: next is only mutable during parsing, so we cast to allow this. - token = token.next || ((token: any).next = readToken(this, token)); + token = token.next ?? ((token: any).next = readToken(this, token)); } while (token.kind === TokenKind.COMMENT); } return token; diff --git a/src/language/parser.js b/src/language/parser.js index faf8ff039d..4ada62dcbd 100644 --- a/src/language/parser.js +++ b/src/language/parser.js @@ -1482,7 +1482,7 @@ class Parser { * is encountered. */ unexpected(atToken?: ?Token): GraphQLError { - const token = atToken || this._lexer.token; + const token = atToken ?? this._lexer.token; return syntaxError( this._lexer.source, token.start, diff --git a/src/language/printer.js b/src/language/printer.js index 85b45ba053..aeff16b140 100644 --- a/src/language/printer.js +++ b/src/language/printer.js @@ -256,7 +256,7 @@ function addDescription(cb) { * print all items together separated by separator if provided */ function join(maybeArray: ?Array, separator = '') { - return maybeArray?.filter(x => x).join(separator) || ''; + return maybeArray?.filter(x => x).join(separator) ?? ''; } /** diff --git a/src/language/visitor.js b/src/language/visitor.js index b5e2f85be7..e310ecdefc 100644 --- a/src/language/visitor.js +++ b/src/language/visitor.js @@ -332,7 +332,7 @@ export function visit( } else { stack = { inArray, index, keys, edits, prev: stack }; inArray = Array.isArray(node); - keys = inArray ? node : visitorKeys[node.kind] || []; + keys = inArray ? node : visitorKeys[node.kind] ?? []; index = -1; edits = []; if (parent) { diff --git a/src/subscription/subscribe.js b/src/subscription/subscribe.js index 99cad61a1c..1b170800c6 100644 --- a/src/subscription/subscribe.js +++ b/src/subscription/subscribe.js @@ -251,7 +251,7 @@ export function createSourceEventStream( // Call the `subscribe()` resolver or the default resolver to produce an // AsyncIterable yielding raw payloads. - const resolveFn = fieldDef.subscribe || exeContext.fieldResolver; + const resolveFn = fieldDef.subscribe ?? exeContext.fieldResolver; const path = addPath(undefined, responseName); diff --git a/src/type/definition.js b/src/type/definition.js index 8ab7939cd8..6f1b737498 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -575,13 +575,13 @@ export class GraphQLScalarType { extensionASTNodes: ?$ReadOnlyArray; constructor(config: $ReadOnly>): void { - const parseValue = config.parseValue || identityFunc; + const parseValue = config.parseValue ?? identityFunc; this.name = config.name; this.description = config.description; - this.serialize = config.serialize || identityFunc; + this.serialize = config.serialize ?? identityFunc; this.parseValue = parseValue; this.parseLiteral = - config.parseLiteral || (node => parseValue(valueFromASTUntyped(node))); + config.parseLiteral ?? (node => parseValue(valueFromASTUntyped(node))); this.extensions = config.extensions && toObjMap(config.extensions); this.astNode = config.astNode; this.extensionASTNodes = undefineIfEmpty(config.extensionASTNodes); @@ -777,7 +777,7 @@ function defineInterfaces( | GraphQLInterfaceTypeConfig, >, ): Array { - const interfaces = resolveThunk(config.interfaces) || []; + const interfaces = resolveThunk(config.interfaces) ?? []; devAssert( Array.isArray(interfaces), `${config.name} interfaces must be an Array or a function which returns an Array.`, @@ -812,7 +812,7 @@ function defineFieldMap( `provided, but got: ${inspect(fieldConfig.resolve)}.`, ); - const argsConfig = fieldConfig.args || {}; + const argsConfig = fieldConfig.args ?? {}; devAssert( isPlainObj(argsConfig), `${config.name}.${fieldName} args must be an object with argument names as keys.`, diff --git a/src/type/directives.js b/src/type/directives.js index 6098a4167a..d3ed6fdae9 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -65,7 +65,7 @@ export class GraphQLDirective { this.name = config.name; this.description = config.description; this.locations = config.locations; - this.isRepeatable = config.isRepeatable || false; + this.isRepeatable = config.isRepeatable ?? false; this.extensions = config.extensions && toObjMap(config.extensions); this.astNode = config.astNode; @@ -75,7 +75,7 @@ export class GraphQLDirective { `@${config.name} locations must be an Array.`, ); - const args = config.args || {}; + const args = config.args ?? {}; devAssert( isObjectLike(args) && !Array.isArray(args), `@${config.name} args must be an object with argument names as keys.`, diff --git a/src/type/schema.js b/src/type/schema.js index 330d7f716b..316b1c0b99 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -167,7 +167,7 @@ export class GraphQLSchema { this._mutationType = config.mutation; this._subscriptionType = config.subscription; // Provide specified directives (e.g. @include and @skip) by default. - this._directives = config.directives || specifiedDirectives; + this._directives = config.directives ?? specifiedDirectives; // To preserve order of user-provided types, we add first to add them to // the set of "collected" types, so `collectReferencedTypes` ignore them. @@ -289,7 +289,7 @@ export class GraphQLSchema { interfaces: /* $ReadOnly */ Array, |} { const implementations = this._implementationsMap[interfaceType.name]; - return implementations || { objects: [], interfaces: [] }; + return implementations ?? { objects: [], interfaces: [] }; } // @deprecated: use isSubType instead - will be removed in v16. diff --git a/src/type/validate.js b/src/type/validate.js index 010ed3549e..1a68afc583 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -188,7 +188,7 @@ function validateName( node: { +name: string, +astNode: ?ASTNode, ... }, ): void { // Ensure names are valid, however introspection types opt out. - const error = isValidNameError(node.name, node.astNode || undefined); + const error = isValidNameError(node.name, node.astNode ?? undefined); if (error) { context.addError(error); } @@ -578,7 +578,7 @@ function getAllNodes( ? extensionASTNodes ? [astNode].concat(extensionASTNodes) : [astNode] - : extensionASTNodes || []; + : extensionASTNodes ?? []; } function getAllSubNodes( @@ -586,7 +586,7 @@ function getAllSubNodes( getter: (T | K) => ?(L | $ReadOnlyArray), ): $ReadOnlyArray { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - return flatMap(getAllNodes(object), item => getter(item) || []); + return flatMap(getAllNodes(object), item => getter(item) ?? []); } function getAllImplementsInterfaceNodes( diff --git a/src/utilities/TypeInfo.js b/src/utilities/TypeInfo.js index 6562294ece..5d9298d855 100644 --- a/src/utilities/TypeInfo.js +++ b/src/utilities/TypeInfo.js @@ -77,7 +77,7 @@ export class TypeInfo { this._directive = null; this._argument = null; this._enumValue = null; - this._getFieldDef = getFieldDefFn || getFieldDef; + this._getFieldDef = getFieldDefFn ?? getFieldDef; if (initialType) { if (isInputType(initialType)) { this._inputTypeStack.push(initialType); @@ -205,7 +205,7 @@ export class TypeInfo { case Kind.ARGUMENT: { let argDef; let argType: mixed; - const fieldOrDirective = this.getDirective() || this.getFieldDef(); + const fieldOrDirective = this.getDirective() ?? this.getFieldDef(); if (fieldOrDirective) { argDef = find( fieldOrDirective.args, diff --git a/src/utilities/__tests__/buildASTSchema-test.js b/src/utilities/__tests__/buildASTSchema-test.js index 2d78eb0c33..902941272a 100644 --- a/src/utilities/__tests__/buildASTSchema-test.js +++ b/src/utilities/__tests__/buildASTSchema-test.js @@ -11,6 +11,7 @@ import { parse } from '../../language/parser'; import { print } from '../../language/printer'; import { validateSchema } from '../../type/validate'; +import { __Schema } from '../../type/introspection'; import { assertDirective, GraphQLSkipDirective, @@ -43,10 +44,11 @@ import { buildASTSchema, buildSchema } from '../buildASTSchema'; * the SDL, parsed in a schema AST, materializing that schema AST into an * in-memory GraphQLSchema, and then finally printing that object into the SDL */ -function cycleSDL(sdl, options = {}) { - const commentDescriptions = options.commentDescriptions || false; +function cycleSDL(sdl, options) { const ast = parse(sdl); const schema = buildASTSchema(ast, options); + + const commentDescriptions = options?.commentDescriptions; return printSchema(schema, { commentDescriptions }); } @@ -1046,6 +1048,20 @@ describe('Schema Builder', () => { expect(errors).to.have.lengthOf.above(0); }); + it('Do not override standard types', () => { + // NOTE: not sure it's desired behaviour to just silently ignore override + // attempts so just documenting it here. + + const schema = buildSchema(` + scalar ID + + scalar __Schema + `); + + expect(schema.getType('ID')).to.equal(GraphQLID); + expect(schema.getType('__Schema')).to.equal(__Schema); + }); + it('Rejects invalid SDL', () => { const sdl = ` type Query { diff --git a/src/utilities/__tests__/stripIgnoredCharacters-test.js b/src/utilities/__tests__/stripIgnoredCharacters-test.js index 42ad82eeaf..5391806f34 100644 --- a/src/utilities/__tests__/stripIgnoredCharacters-test.js +++ b/src/utilities/__tests__/stripIgnoredCharacters-test.js @@ -69,7 +69,7 @@ function lexValue(str) { // Called only to make error messages for failing tests /* istanbul ignore next */ function inspectStr(str) { - return (JSON.stringify(str) || '') + return (JSON.stringify(str) ?? '') .replace(/^"|"$/g, '`') .replace(/\\"/g, '"'); } diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index 5e5dbed2bb..869f3c6f4b 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -123,17 +123,16 @@ export function buildSchema( options?: {| ...BuildSchemaOptions, ...ParseOptions |}, ): GraphQLSchema { const document = parse(source, { - noLocation: options?.noLocation || false, - allowLegacySDLEmptyFields: options?.allowLegacySDLEmptyFields || false, + noLocation: options?.noLocation, + allowLegacySDLEmptyFields: options?.allowLegacySDLEmptyFields, allowLegacySDLImplementsInterfaces: - options?.allowLegacySDLImplementsInterfaces || false, - experimentalFragmentVariables: - options?.experimentalFragmentVariables || false, + options?.allowLegacySDLImplementsInterfaces, + experimentalFragmentVariables: options?.experimentalFragmentVariables, }); return buildASTSchema(document, { - commentDescriptions: options?.commentDescriptions || false, - assumeValidSDL: options?.assumeValidSDL || false, - assumeValid: options?.assumeValid || false, + commentDescriptions: options?.commentDescriptions, + assumeValidSDL: options?.assumeValidSDL, + assumeValid: options?.assumeValid, }); } diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index be93160dc2..4c32a966ad 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -203,7 +203,7 @@ export function extendSchemaImpl( for (const typeNode of typeDefs) { const name = typeNode.name.value; - typeMap[name] = stdTypeMap[name] || buildType(typeNode); + typeMap[name] = stdTypeMap[name] ?? buildType(typeNode); } const operationTypes = { @@ -227,12 +227,12 @@ export function extendSchemaImpl( ...directiveDefs.map(buildDirective), ], extensions: undefined, - astNode: schemaDef || schemaConfig.astNode, + astNode: schemaDef ?? schemaConfig.astNode, extensionASTNodes: concatMaybeArrays( schemaConfig.extensionASTNodes, schemaExtensions, ), - assumeValid: options?.assumeValid || false, + assumeValid: options?.assumeValid ?? false, }; // Below are functions used for producing this schema that have closed over @@ -294,7 +294,7 @@ export function extendSchemaImpl( type: GraphQLInputObjectType, ): GraphQLInputObjectType { const config = type.toConfig(); - const extensions = typeExtensionsMap[config.name] || []; + const extensions = typeExtensionsMap[config.name] ?? []; return new GraphQLInputObjectType({ ...config, @@ -314,7 +314,7 @@ export function extendSchemaImpl( function extendEnumType(type: GraphQLEnumType): GraphQLEnumType { const config = type.toConfig(); - const extensions = typeExtensionsMap[type.name] || []; + const extensions = typeExtensionsMap[type.name] ?? []; return new GraphQLEnumType({ ...config, @@ -331,7 +331,7 @@ export function extendSchemaImpl( function extendScalarType(type: GraphQLScalarType): GraphQLScalarType { const config = type.toConfig(); - const extensions = typeExtensionsMap[config.name] || []; + const extensions = typeExtensionsMap[config.name] ?? []; return new GraphQLScalarType({ ...config, @@ -344,7 +344,7 @@ export function extendSchemaImpl( function extendObjectType(type: GraphQLObjectType): GraphQLObjectType { const config = type.toConfig(); - const extensions = typeExtensionsMap[config.name] || []; + const extensions = typeExtensionsMap[config.name] ?? []; return new GraphQLObjectType({ ...config, @@ -367,7 +367,7 @@ export function extendSchemaImpl( type: GraphQLInterfaceType, ): GraphQLInterfaceType { const config = type.toConfig(); - const extensions = typeExtensionsMap[config.name] || []; + const extensions = typeExtensionsMap[config.name] ?? []; return new GraphQLInterfaceType({ ...config, @@ -388,7 +388,7 @@ export function extendSchemaImpl( function extendUnionType(type: GraphQLUnionType): GraphQLUnionType { const config = type.toConfig(); - const extensions = typeExtensionsMap[config.name] || []; + const extensions = typeExtensionsMap[config.name] ?? []; return new GraphQLUnionType({ ...config, @@ -431,7 +431,7 @@ export function extendSchemaImpl( const opTypes: any = {}; for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const operationTypesNodes = node.operationTypes || []; + const operationTypesNodes = node.operationTypes ?? []; for (const operationType of operationTypesNodes) { opTypes[operationType.operation] = getNamedType(operationType.type); @@ -442,7 +442,7 @@ export function extendSchemaImpl( function getNamedType(node: NamedTypeNode): GraphQLNamedType { const name = node.name.value; - const type = stdTypeMap[name] || typeMap[name]; + const type = stdTypeMap[name] ?? typeMap[name]; if (type === undefined) { throw new Error(`Unknown type: "${name}".`); @@ -486,7 +486,7 @@ export function extendSchemaImpl( const fieldConfigMap = Object.create(null); for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const nodeFields = node.fields || []; + const nodeFields = node.fields ?? []; for (const field of nodeFields) { fieldConfigMap[field.name.value] = { @@ -508,7 +508,7 @@ export function extendSchemaImpl( args: ?$ReadOnlyArray, ): GraphQLFieldConfigArgumentMap { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argsNodes = args || []; + const argsNodes = args ?? []; const argConfigMap = Object.create(null); for (const arg of argsNodes) { @@ -535,7 +535,7 @@ export function extendSchemaImpl( const inputFieldMap = Object.create(null); for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const fieldsNodes = node.fields || []; + const fieldsNodes = node.fields ?? []; for (const field of fieldsNodes) { // Note: While this could make assertions to get the correctly typed @@ -560,7 +560,7 @@ export function extendSchemaImpl( const enumValueMap = Object.create(null); for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const valuesNodes = node.values || []; + const valuesNodes = node.values ?? []; for (const value of valuesNodes) { enumValueMap[value.name.value] = { @@ -584,7 +584,7 @@ export function extendSchemaImpl( const interfaces = []; for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const interfacesNodes = node.interfaces || []; + const interfacesNodes = node.interfaces ?? []; for (const type of interfacesNodes) { // Note: While this could make assertions to get the correctly typed @@ -603,7 +603,7 @@ export function extendSchemaImpl( const types = []; for (const node of nodes) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const typeNodes = node.types || []; + const typeNodes = node.types ?? []; for (const type of typeNodes) { // Note: While this could make assertions to get the correctly typed @@ -619,7 +619,7 @@ export function extendSchemaImpl( function buildType(astNode: TypeDefinitionNode): GraphQLNamedType { const name = astNode.name.value; const description = getDescription(astNode, options); - const extensionNodes = typeExtensionsMap[name] || []; + const extensionNodes = typeExtensionsMap[name] ?? []; switch (astNode.kind) { case Kind.OBJECT_TYPE_DEFINITION: { diff --git a/src/validation/rules/FieldsOnCorrectTypeRule.js b/src/validation/rules/FieldsOnCorrectTypeRule.js index d51b5e4a31..0e6d74d406 100644 --- a/src/validation/rules/FieldsOnCorrectTypeRule.js +++ b/src/validation/rules/FieldsOnCorrectTypeRule.js @@ -102,7 +102,7 @@ function getSuggestedTypeNames( // This interface type defines this field. suggestedTypes.add(possibleInterface); usageCount[possibleInterface.name] = - (usageCount[possibleInterface.name] || 0) + 1; + (usageCount[possibleInterface.name] ?? 0) + 1; } } diff --git a/src/validation/rules/KnownArgumentNamesRule.js b/src/validation/rules/KnownArgumentNamesRule.js index d84f243dae..57f280aa6b 100644 --- a/src/validation/rules/KnownArgumentNamesRule.js +++ b/src/validation/rules/KnownArgumentNamesRule.js @@ -65,7 +65,7 @@ export function KnownArgumentNamesOnDirectives( for (const def of astDefinitions) { if (def.kind === Kind.DIRECTIVE_DEFINITION) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argsNodes = def.arguments || []; + const argsNodes = def.arguments ?? []; directiveArgs[def.name.value] = argsNodes.map(arg => arg.name.value); } diff --git a/src/validation/rules/KnownTypeNamesRule.js b/src/validation/rules/KnownTypeNamesRule.js index 99c83e5ee0..2c71a3888c 100644 --- a/src/validation/rules/KnownTypeNamesRule.js +++ b/src/validation/rules/KnownTypeNamesRule.js @@ -47,7 +47,7 @@ export function KnownTypeNamesRule( NamedType(node, _1, parent, _2, ancestors) { const typeName = node.name.value; if (!existingTypesMap[typeName] && !definedTypes[typeName]) { - const definitionNode = ancestors[2] || parent; + const definitionNode = ancestors[2] ?? parent; const isSDL = definitionNode != null && isSDLNode(definitionNode); if (isSDL && isSpecifiedScalarName(typeName)) { return; diff --git a/src/validation/rules/LoneSchemaDefinitionRule.js b/src/validation/rules/LoneSchemaDefinitionRule.js index 549293c2fb..cd0ff8b68d 100644 --- a/src/validation/rules/LoneSchemaDefinitionRule.js +++ b/src/validation/rules/LoneSchemaDefinitionRule.js @@ -15,9 +15,9 @@ export function LoneSchemaDefinitionRule( ): ASTVisitor { const oldSchema = context.getSchema(); const alreadyDefined = - oldSchema?.astNode || - oldSchema?.getQueryType() || - oldSchema?.getMutationType() || + oldSchema?.astNode ?? + oldSchema?.getQueryType() ?? + oldSchema?.getMutationType() ?? oldSchema?.getSubscriptionType(); let schemaDefinitionsCount = 0; diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js index dbf272ba19..15a6f7bcea 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js @@ -572,9 +572,9 @@ function findConflict( } /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const args1 = node1.arguments || []; + const args1 = node1.arguments ?? []; /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const args2 = node2.arguments || []; + const args2 = node2.arguments ?? []; // Two field calls must have the same arguments. if (!sameArguments(args1, args2)) { return [ diff --git a/src/validation/rules/ProvidedRequiredArgumentsRule.js b/src/validation/rules/ProvidedRequiredArgumentsRule.js index ce3f12464a..1033cd88aa 100644 --- a/src/validation/rules/ProvidedRequiredArgumentsRule.js +++ b/src/validation/rules/ProvidedRequiredArgumentsRule.js @@ -37,7 +37,7 @@ export function ProvidedRequiredArgumentsRule( } /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argNodes = fieldNode.arguments || []; + const argNodes = fieldNode.arguments ?? []; const argNodeMap = keyMap(argNodes, arg => arg.name.value); for (const argDef of fieldDef.args) { const argNode = argNodeMap[argDef.name]; @@ -79,7 +79,7 @@ export function ProvidedRequiredArgumentsOnDirectives( for (const def of astDefinitions) { if (def.kind === Kind.DIRECTIVE_DEFINITION) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argNodes = def.arguments || []; + const argNodes = def.arguments ?? []; requiredArgsMap[def.name.value] = keyMap( argNodes.filter(isRequiredArgumentNode), @@ -96,7 +96,7 @@ export function ProvidedRequiredArgumentsOnDirectives( const requiredArgs = requiredArgsMap[directiveName]; if (requiredArgs) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const argNodes = directiveNode.arguments || []; + const argNodes = directiveNode.arguments ?? []; const argNodeMap = keyMap(argNodes, arg => arg.name.value); for (const argName of Object.keys(requiredArgs)) { if (!argNodeMap[argName]) { diff --git a/src/validation/rules/UniqueEnumValueNamesRule.js b/src/validation/rules/UniqueEnumValueNamesRule.js index 56426362dd..dac1939abd 100644 --- a/src/validation/rules/UniqueEnumValueNamesRule.js +++ b/src/validation/rules/UniqueEnumValueNamesRule.js @@ -31,7 +31,7 @@ export function UniqueEnumValueNamesRule( } /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const valueNodes = node.values || []; + const valueNodes = node.values ?? []; const valueNames = knownValueNames[typeName]; for (const valueDef of valueNodes) { diff --git a/src/validation/rules/UniqueFieldDefinitionNamesRule.js b/src/validation/rules/UniqueFieldDefinitionNamesRule.js index 20608df895..2a75e5b89b 100644 --- a/src/validation/rules/UniqueFieldDefinitionNamesRule.js +++ b/src/validation/rules/UniqueFieldDefinitionNamesRule.js @@ -39,7 +39,7 @@ export function UniqueFieldDefinitionNamesRule( } /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const fieldNodes = node.fields || []; + const fieldNodes = node.fields ?? []; const fieldNames = knownFieldNames[typeName]; for (const fieldDef of fieldNodes) { diff --git a/src/validation/rules/UniqueOperationTypesRule.js b/src/validation/rules/UniqueOperationTypesRule.js index a5e25eb840..2cd40fc532 100644 --- a/src/validation/rules/UniqueOperationTypesRule.js +++ b/src/validation/rules/UniqueOperationTypesRule.js @@ -30,7 +30,7 @@ export function UniqueOperationTypesRule( function checkOperationTypes(node) { /* istanbul ignore next (See https://github.com/graphql/graphql-js/issues/2203) */ - const operationTypesNodes = node.operationTypes || []; + const operationTypesNodes = node.operationTypes ?? []; for (const operationType of operationTypesNodes) { const operation = operationType.operation;