From aba2bbb07ba88cef57d0a2c290978bf4d9ee8a85 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Wed, 7 Aug 2024 14:27:35 +0200 Subject: [PATCH] Lint files --- src/execution/collectFields.ts | 16 ++++-- src/execution/execute.ts | 49 ++++++++++++++----- src/execution/subscribe.ts | 14 ++++-- src/execution/values.ts | 13 +++-- src/language/__tests__/printer-test.ts | 3 +- src/language/parser.ts | 6 +-- src/language/printer.ts | 5 +- src/utilities/TypeInfo.ts | 3 +- .../rules/SingleFieldSubscriptionsRule.ts | 4 +- 9 files changed, 81 insertions(+), 32 deletions(-) diff --git a/src/execution/collectFields.ts b/src/execution/collectFields.ts index 7c9d608bfe..004a0337aa 100644 --- a/src/execution/collectFields.ts +++ b/src/execution/collectFields.ts @@ -51,7 +51,7 @@ export function collectFields( selectionSet, fields, new Set(), - undefined + undefined, ); return fields; } @@ -111,9 +111,17 @@ function collectFieldsImpl( const name = getFieldEntryKey(selection); const fieldList = fields.get(name); if (fieldList !== undefined) { - fieldList.push({ node: selection, fragmentVariableValues: localVariableValues ?? undefined }); + fieldList.push({ + node: selection, + fragmentVariableValues: localVariableValues ?? undefined, + }); } else { - fields.set(name, [{ node: selection, fragmentVariableValues: localVariableValues ?? undefined }]); + fields.set(name, [ + { + node: selection, + fragmentVariableValues: localVariableValues ?? undefined, + }, + ]); } break; } @@ -179,7 +187,7 @@ function collectFieldsImpl( fragment.selectionSet, fields, visitedFragmentNames, - fragmentVariableValues + fragmentVariableValues, ); break; } diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 0a501dab0b..d11900976b 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -52,10 +52,10 @@ import { import type { GraphQLSchema } from '../type/schema'; import { assertValidSchema } from '../type/validate'; +import type { FieldDetails } from './collectFields'; import { collectFields, collectSubfields as _collectSubfields, - FieldDetails, } from './collectFields'; import { getArgumentValues, getVariableValues } from './values'; @@ -523,7 +523,7 @@ function executeField( fieldEntries[0].node, fieldDef.args, exeContext.variableValues, - fieldEntries[0].fragmentVariableValues + fieldEntries[0].fragmentVariableValues, ); // The resolve function's optional third argument is a context value that @@ -536,7 +536,14 @@ function executeField( let completed; if (isPromise(result)) { completed = result.then((resolved) => - completeValue(exeContext, returnType, fieldEntries, info, path, resolved), + completeValue( + exeContext, + returnType, + fieldEntries, + info, + path, + resolved, + ), ); } else { completed = completeValue( @@ -553,13 +560,21 @@ function executeField( // Note: we don't rely on a `catch` method, but we do expect "thenable" // to take a second callback for the error case. return completed.then(undefined, (rawError) => { - const error = locatedError(rawError, fieldEntries.map(entry => entry.node), pathToArray(path)); + const error = locatedError( + rawError, + fieldEntries.map((entry) => entry.node), + pathToArray(path), + ); return handleFieldError(error, returnType, exeContext); }); } return completed; } catch (rawError) { - const error = locatedError(rawError, fieldEntries.map(entry => entry.node), pathToArray(path)); + const error = locatedError( + rawError, + fieldEntries.map((entry) => entry.node), + pathToArray(path), + ); return handleFieldError(error, returnType, exeContext); } } @@ -578,7 +593,7 @@ export function buildResolveInfo( // information about the current execution state. return { fieldName: fieldDef.name, - fieldNodes: fieldEntries.map(entry => entry.node), + fieldNodes: fieldEntries.map((entry) => entry.node), returnType: fieldDef.type, parentType, path, @@ -772,7 +787,7 @@ function completeListValue( return completedItem.then(undefined, (rawError) => { const error = locatedError( rawError, - fieldEntries.map(entry => entry.node), + fieldEntries.map((entry) => entry.node), pathToArray(itemPath), ); return handleFieldError(error, itemType, exeContext); @@ -780,7 +795,11 @@ function completeListValue( } return completedItem; } catch (rawError) { - const error = locatedError(rawError, fieldEntries.map(entry => entry.node), pathToArray(itemPath)); + const error = locatedError( + rawError, + fieldEntries.map((entry) => entry.node), + pathToArray(itemPath), + ); return handleFieldError(error, itemType, exeContext); } }); @@ -822,7 +841,7 @@ function completeAbstractValue( const contextValue = exeContext.contextValue; const runtimeType = resolveTypeFn(result, contextValue, info, returnType); - const fieldNodes = fieldEntries.map(entry => entry.node) + const fieldNodes = fieldEntries.map((entry) => entry.node); if (isPromise(runtimeType)) { return runtimeType.then((resolvedRuntimeType) => completeObjectValue( @@ -938,7 +957,11 @@ function completeObjectValue( if (isPromise(isTypeOf)) { return isTypeOf.then((resolvedIsTypeOf) => { if (!resolvedIsTypeOf) { - throw invalidReturnTypeError(returnType, result, fieldEntries.map(entry => entry.node)); + throw invalidReturnTypeError( + returnType, + result, + fieldEntries.map((entry) => entry.node), + ); } return executeFields( exeContext, @@ -951,7 +974,11 @@ function completeObjectValue( } if (!isTypeOf) { - throw invalidReturnTypeError(returnType, result, fieldEntries.map(entry => entry.node)); + throw invalidReturnTypeError( + returnType, + result, + fieldEntries.map((entry) => entry.node), + ); } } diff --git a/src/execution/subscribe.ts b/src/execution/subscribe.ts index 7b42278a96..caf3c7617f 100644 --- a/src/execution/subscribe.ts +++ b/src/execution/subscribe.ts @@ -221,7 +221,7 @@ async function executeSubscription( const fieldName = fieldEntries[0].node.name.value; throw new GraphQLError( `The subscription field "${fieldName}" is not defined.`, - { nodes: fieldEntries.map(entry => entry.node) }, + { nodes: fieldEntries.map((entry) => entry.node) }, ); } @@ -240,7 +240,11 @@ async function executeSubscription( // Build a JS object of arguments from the field.arguments AST, using the // variables scope to fulfill any variable references. - const args = getArgumentValues(fieldEntries[0].node, fieldDef.args, variableValues); + const args = getArgumentValues( + fieldEntries[0].node, + fieldDef.args, + variableValues, + ); // The resolve function's optional third argument is a context value that // is provided to every resolve function within an execution. It is commonly @@ -257,6 +261,10 @@ async function executeSubscription( } return eventStream; } catch (error) { - throw locatedError(error, fieldEntries.map(entry => entry.node), pathToArray(path)); + throw locatedError( + error, + fieldEntries.map((entry) => entry.node), + pathToArray(path), + ); } } diff --git a/src/execution/values.ts b/src/execution/values.ts index e37ea168b2..c1050cc6ef 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -15,7 +15,7 @@ import type { import { Kind } from '../language/kinds'; import { print } from '../language/printer'; -import type { GraphQLArgument, GraphQLField } from '../type/definition'; +import type { GraphQLArgument } from '../type/definition'; import { isInputType, isNonNullType } from '../type/definition'; import type { GraphQLDirective } from '../type/directives'; import type { GraphQLSchema } from '../type/schema'; @@ -23,7 +23,7 @@ import type { GraphQLSchema } from '../type/schema'; import { coerceInputValue } from '../utilities/coerceInputValue'; import { typeFromAST } from '../utilities/typeFromAST'; import { valueFromAST } from '../utilities/valueFromAST'; -import { valueFromASTUntyped } from '../utilities'; +import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped'; type CoercedVariableValues = | { errors: ReadonlyArray; coerced?: never } @@ -191,12 +191,15 @@ export function getArgumentValues( fragmentArgValues != null && hasOwnProperty(fragmentArgValues, variableName) ) { - hasValue = fragmentArgValues![variableName] != null; + hasValue = fragmentArgValues[variableName] != null; if (!hasValue && argDef.defaultValue !== undefined) { coercedValues[name] = argDef.defaultValue; continue; } - } else if (variableValues != null && hasOwnProperty(variableValues, variableName)) { + } else if ( + variableValues != null && + hasOwnProperty(variableValues, variableName) + ) { hasValue = variableValues[variableName] != null; } else if (argDef.defaultValue !== undefined) { coercedValues[name] = argDef.defaultValue; @@ -248,7 +251,7 @@ export function getArgumentValuesFromSpread( fragmentArgValues?: Maybe>, ): { [argument: string]: unknown } { const coercedValues: { [argument: string]: unknown } = {}; - const argNodeMap = keyMap(node?.arguments || [], (arg) => arg.name.value); + const argNodeMap = keyMap(node?.arguments ?? [], (arg) => arg.name.value); for (const varDef of fragmentVarDefs) { const name = varDef.variable.name.value; diff --git a/src/language/__tests__/printer-test.ts b/src/language/__tests__/printer-test.ts index fc45657166..13ad9ce6c6 100644 --- a/src/language/__tests__/printer-test.ts +++ b/src/language/__tests__/printer-test.ts @@ -239,7 +239,6 @@ describe('Printer: Query document', () => { c: "a long string extending arguments over max length" ) } - ` - ); + `); }); }); diff --git a/src/language/parser.ts b/src/language/parser.ts index 045569138f..d4504d2271 100644 --- a/src/language/parser.ts +++ b/src/language/parser.ts @@ -123,7 +123,7 @@ export interface ParseOptions { * } * ``` */ - experimentalFragmentArguments?: boolean | undefined; + experimentalFragmentArguments?: boolean | undefined; } /** @@ -555,13 +555,13 @@ export class Parser { kind: Kind.FRAGMENT_DEFINITION, name: this.parseFragmentName(), variableDefinitions: - this._options.experimentalFragmentArguments === true || this._options.allowLegacyFragmentVariables === true + this._options.experimentalFragmentArguments === true || + this._options.allowLegacyFragmentVariables === true ? this.parseVariableDefinitions() : undefined, typeCondition: (this.expectKeyword('on'), this.parseNamedType()), directives: this.parseDirectives(false), selectionSet: this.parseSelectionSet(), - }); } diff --git a/src/language/printer.ts b/src/language/printer.ts index 476187f09e..673d3e69fc 100644 --- a/src/language/printer.ts +++ b/src/language/printer.ts @@ -58,7 +58,10 @@ const printDocASTReducer: ASTReducer = { leave({ alias, name, arguments: args, directives, selectionSet }) { const prefix = wrap('', alias, ': ') + name; - return join([wrappedLineAndArgs(prefix, args), join(directives, ' '), selectionSet], ' '); + return join( + [wrappedLineAndArgs(prefix, args), join(directives, ' '), selectionSet], + ' ', + ); }, }, diff --git a/src/utilities/TypeInfo.ts b/src/utilities/TypeInfo.ts index 979f506e74..160a93fffb 100644 --- a/src/utilities/TypeInfo.ts +++ b/src/utilities/TypeInfo.ts @@ -228,7 +228,8 @@ export class TypeInfo { if (directive) { argDef = directive.args.find((arg) => arg.name === node.name.value); } else if (fragmentSpread) { - const fragmentDef = this._fragmentDefinitions[fragmentSpread.name.value] + const fragmentDef = + this._fragmentDefinitions[fragmentSpread.name.value]; const fragVarDef = fragmentDef?.variableDefinitions?.find( (varDef) => varDef.variable.name.value === node.name.value, ); diff --git a/src/validation/rules/SingleFieldSubscriptionsRule.ts b/src/validation/rules/SingleFieldSubscriptionsRule.ts index ff9f33fec7..a93aeeb224 100644 --- a/src/validation/rules/SingleFieldSubscriptionsRule.ts +++ b/src/validation/rules/SingleFieldSubscriptionsRule.ts @@ -57,7 +57,7 @@ export function SingleFieldSubscriptionsRule( operationName != null ? `Subscription "${operationName}" must select only one top level field.` : 'Anonymous Subscription must select only one top level field.', - { nodes: extraFieldSelections.map(entry => entry.node) }, + { nodes: extraFieldSelections.map((entry) => entry.node) }, ), ); } @@ -70,7 +70,7 @@ export function SingleFieldSubscriptionsRule( operationName != null ? `Subscription "${operationName}" must not select an introspection top level field.` : 'Anonymous Subscription must not select an introspection top level field.', - { nodes: fieldNodes.map(entry => entry.node) }, + { nodes: fieldNodes.map((entry) => entry.node) }, ), ); }