Skip to content

Commit

Permalink
Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Aug 7, 2024
1 parent 7819043 commit aba2bbb
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 32 deletions.
16 changes: 12 additions & 4 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function collectFields(
selectionSet,
fields,
new Set(),
undefined
undefined,
);
return fields;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -179,7 +187,7 @@ function collectFieldsImpl(
fragment.selectionSet,
fields,
visitedFragmentNames,
fragmentVariableValues
fragmentVariableValues,
);
break;
}
Expand Down
49 changes: 38 additions & 11 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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);
}
}
Expand All @@ -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,
Expand Down Expand Up @@ -772,15 +787,19 @@ 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);
});
}
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);
}
});
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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),
);
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/execution/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
);
}

Expand All @@ -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
Expand All @@ -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),
);
}
}
13 changes: 8 additions & 5 deletions src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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';

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<GraphQLError>; coerced?: never }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -248,7 +251,7 @@ export function getArgumentValuesFromSpread(
fragmentArgValues?: Maybe<ObjMap<unknown>>,
): { [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;
Expand Down
3 changes: 1 addition & 2 deletions src/language/__tests__/printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ describe('Printer: Query document', () => {
c: "a long string extending arguments over max length"
)
}
`
);
`);
});
});
6 changes: 3 additions & 3 deletions src/language/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface ParseOptions {
* }
* ```
*/
experimentalFragmentArguments?: boolean | undefined;
experimentalFragmentArguments?: boolean | undefined;
}

/**
Expand Down Expand Up @@ -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(),

});
}

Expand Down
5 changes: 4 additions & 1 deletion src/language/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ const printDocASTReducer: ASTReducer<string> = {
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],
' ',
);
},
},

Expand Down
3 changes: 2 additions & 1 deletion src/utilities/TypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions src/validation/rules/SingleFieldSubscriptionsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
),
);
}
Expand All @@ -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) },
),
);
}
Expand Down

0 comments on commit aba2bbb

Please sign in to comment.