From cd55ba93f2981be091cd180eac67dd9d296ec409 Mon Sep 17 00:00:00 2001 From: saihaj Date: Tue, 20 Oct 2020 15:57:23 -0500 Subject: [PATCH] convert `mixed` (flow) to `unknown` (TS) --- src/error/GraphQLError.ts | 6 +- src/error/formatError.ts | 2 +- src/error/locatedError.ts | 2 +- src/execution/__tests__/abstract-test.ts | 4 +- src/execution/__tests__/lists-test.ts | 8 +- src/execution/__tests__/nonnull-test.ts | 4 +- src/execution/__tests__/resolve-test.ts | 2 +- src/execution/__tests__/variables-test.ts | 2 +- src/execution/execute.ts | 84 ++++----- src/execution/values.ts | 20 +- src/graphql.ts | 6 +- src/jsutils/__tests__/inspect-test.ts | 6 +- src/jsutils/devAssert.ts | 2 +- src/jsutils/inspect.ts | 10 +- src/jsutils/instanceOf.ts | 6 +- src/jsutils/invariant.ts | 2 +- src/jsutils/isAsyncIterable.ts | 2 +- src/jsutils/isCollection.ts | 2 +- src/jsutils/isObjectLike.ts | 2 +- src/jsutils/isPromise.ts | 2 +- src/jsutils/memoize3.ts | 8 +- src/language/__tests__/schema-parser-test.ts | 18 +- src/language/__tests__/toJSONDeep.ts | 2 +- src/language/ast.ts | 6 +- src/language/source.ts | 2 +- src/subscription/__tests__/simplePubSub.ts | 2 +- src/subscription/__tests__/subscribe-test.ts | 8 +- src/subscription/mapAsyncIterator.ts | 6 +- src/subscription/subscribe.ts | 18 +- src/type/__tests__/definition-test.ts | 2 +- src/type/__tests__/enumType-test.ts | 2 +- src/type/__tests__/extensions-test.ts | 2 +- src/type/__tests__/predicate-test.ts | 8 +- src/type/__tests__/scalars-test.ts | 20 +- src/type/__tests__/validation-test.ts | 4 +- src/type/definition.ts | 174 +++++++++--------- src/type/directives.ts | 10 +- src/type/introspection.ts | 18 +- src/type/scalars.ts | 22 +-- src/type/schema.ts | 10 +- src/utilities/TypeInfo.ts | 32 ++-- .../__tests__/coerceInputValue-test.ts | 2 +- src/utilities/__tests__/printSchema-test.ts | 2 +- .../__tests__/typeComparators-test.ts | 2 +- src/utilities/__tests__/valueFromAST-test.ts | 2 +- .../__tests__/valueFromASTUntyped-test.ts | 2 +- src/utilities/astFromValue.d.ts | 2 +- src/utilities/astFromValue.ts | 4 +- src/utilities/buildClientSchema.ts | 4 +- src/utilities/coerceInputValue.ts | 12 +- src/utilities/extendSchema.ts | 6 +- src/utilities/findBreakingChanges.ts | 6 +- src/utilities/valueFromAST.d.ts | 2 +- src/utilities/valueFromAST.ts | 8 +- src/utilities/valueFromASTUntyped.ts | 4 +- src/validation/ValidationContext.ts | 4 +- .../rules/OverlappingFieldsCanBeMergedRule.ts | 2 +- .../rules/VariablesInAllowedPositionRule.ts | 2 +- 58 files changed, 307 insertions(+), 307 deletions(-) diff --git a/src/error/GraphQLError.ts b/src/error/GraphQLError.ts index c4026354083..e6320e9a6b4 100644 --- a/src/error/GraphQLError.ts +++ b/src/error/GraphQLError.ts @@ -72,7 +72,7 @@ export class GraphQLError extends Error { /** * Extension fields to add to the formatted error. */ - readonly extensions: { [key: string]: mixed, ... } | void; + readonly extensions: { [key: string]: unknown, ... } | void; constructor( message: string, @@ -80,8 +80,8 @@ export class GraphQLError extends Error { source?: ?Source, positions?: ?ReadonlyArray, path?: ?ReadonlyArray, - originalError?: ?(Error & { readonly extensions?: mixed, ... }), - extensions?: ?{ [key: string]: mixed, ... }, + originalError?: ?(Error & { readonly extensions?: unknown, ... }), + extensions?: ?{ [key: string]: unknown, ... }, ): void { super(message); diff --git a/src/error/formatError.ts b/src/error/formatError.ts index b12ff9a131e..ddfc28687db 100644 --- a/src/error/formatError.ts +++ b/src/error/formatError.ts @@ -46,5 +46,5 @@ export type GraphQLFormattedError = { * Reserved for implementors to extend the protocol however they see fit, * and hence there are no additional restrictions on its contents. */ - readonly extensions?: { [key: string]: mixed, ... }, + readonly extensions?: { [key: string]: unknown, ... }, }; diff --git a/src/error/locatedError.ts b/src/error/locatedError.ts index 16ba70fbb66..b6df51af539 100644 --- a/src/error/locatedError.ts +++ b/src/error/locatedError.ts @@ -10,7 +10,7 @@ import { GraphQLError } from './GraphQLError'; * document responsible for the original Error. */ export function locatedError( - rawOriginalError: mixed, + rawOriginalError: unknown, nodes: ASTNode | ReadonlyArray | void | null, path?: ?ReadonlyArray, ): GraphQLError { diff --git a/src/execution/__tests__/abstract-test.ts b/src/execution/__tests__/abstract-test.ts index 8c77046f349..7efe2efed9c 100644 --- a/src/execution/__tests__/abstract-test.ts +++ b/src/execution/__tests__/abstract-test.ts @@ -19,7 +19,7 @@ import { executeSync, execute } from '../execute'; async function executeQuery(args: { schema: GraphQLSchema, query: string, - rootValue?: mixed, + rootValue?: unknown, }) { const { schema, query, rootValue } = args; const document = parse(query); @@ -533,7 +533,7 @@ describe('Execute: Handles execution of abstract types', () => { } `); - function expectError({ forTypeName }: { forTypeName: mixed }) { + function expectError({ forTypeName }: { forTypeName: unknown }) { const rootValue = { pet: { __typename: forTypeName } }; const result = executeSync({ schema, document, rootValue }); return { diff --git a/src/execution/__tests__/lists-test.ts b/src/execution/__tests__/lists-test.ts index 41f83c26cf3..e2e36e5d47d 100644 --- a/src/execution/__tests__/lists-test.ts +++ b/src/execution/__tests__/lists-test.ts @@ -8,7 +8,7 @@ import { buildSchema } from '../../utilities/buildASTSchema'; import { execute, executeSync } from '../execute'; describe('Execute: Accepts any iterable as list value', () => { - function complete(rootValue: mixed) { + function complete(rootValue: unknown) { return executeSync({ schema: buildSchema('type Query { listField: [String] }'), document: parse('{ listField }'), @@ -65,7 +65,7 @@ describe('Execute: Accepts any iterable as list value', () => { }); describe('Execute: Handles list nullability', () => { - async function complete(args: { listField: mixed, as: string }) { + async function complete(args: { listField: unknown, as: string }) { const { listField, as } = args; const schema = buildSchema(`type Query { listField: ${as} }`); const document = parse('{ listField }'); @@ -85,11 +85,11 @@ describe('Execute: Handles list nullability', () => { } return result; - function executeQuery(listValue: mixed) { + function executeQuery(listValue: unknown) { return execute({ schema, document, rootValue: { listField: listValue } }); } - function promisify(value: mixed): Promise { + function promisify(value: unknown): Promise { return value instanceof Error ? Promise.reject(value) : Promise.resolve(value); diff --git a/src/execution/__tests__/nonnull-test.ts b/src/execution/__tests__/nonnull-test.ts index 4eb38f12b6e..223c552c33d 100644 --- a/src/execution/__tests__/nonnull-test.ts +++ b/src/execution/__tests__/nonnull-test.ts @@ -106,7 +106,7 @@ const schema = buildSchema(` function executeQuery( query: string, - rootValue: mixed, + rootValue: unknown, ): ExecutionResult | Promise { return execute({ schema, document: parse(query), rootValue }); } @@ -122,7 +122,7 @@ function patchData(data: ExecutionResult): ExecutionResult { return JSON.parse(patch(JSON.stringify(data))); } -async function executeSyncAndAsync(query: string, rootValue: mixed) { +async function executeSyncAndAsync(query: string, rootValue: unknown) { const syncResult = executeSync({ schema, document: parse(query), rootValue }); const asyncResult = await execute({ schema, diff --git a/src/execution/__tests__/resolve-test.ts b/src/execution/__tests__/resolve-test.ts index b8d28a615b7..f62314f8dc8 100644 --- a/src/execution/__tests__/resolve-test.ts +++ b/src/execution/__tests__/resolve-test.ts @@ -95,7 +95,7 @@ describe('Execute: resolve function', () => { resolve: (source, args) => JSON.stringify([source, args]), }); - function executeQuery(query: string, rootValue?: mixed) { + function executeQuery(query: string, rootValue?: unknown) { const document = parse(query); return executeSync({ schema, document, rootValue }); } diff --git a/src/execution/__tests__/variables-test.ts b/src/execution/__tests__/variables-test.ts index 9f637dd7edb..ddbf7145ae6 100644 --- a/src/execution/__tests__/variables-test.ts +++ b/src/execution/__tests__/variables-test.ts @@ -119,7 +119,7 @@ const schema = new GraphQLSchema({ query: TestType }); function executeQuery( query: string, - variableValues?: { [variable: string]: mixed, ... }, + variableValues?: { [variable: string]: unknown, ... }, ) { const document = parse(query); return executeSync({ schema, document, variableValues }); diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 562b5c2c35e..1d989e1c20c 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -95,10 +95,10 @@ import { export type ExecutionContext = { schema: GraphQLSchema, fragments: ObjMap, - rootValue: mixed, - contextValue: mixed, + rootValue: unknown, + contextValue: unknown, operation: OperationDefinitionNode, - variableValues: { [variable: string]: mixed, ... }, + variableValues: { [variable: string]: unknown, ... }, fieldResolver: GraphQLFieldResolver, typeResolver: GraphQLTypeResolver, errors: Array, @@ -113,14 +113,14 @@ export type ExecutionContext = { */ export type ExecutionResult = { errors?: ReadonlyArray, - data?: ObjMap | null, - extensions?: ObjMap, + data?: ObjMap | null, + extensions?: ObjMap, }; export type FormattedExecutionResult = { errors?: ReadonlyArray, - data?: ObjMap | null, - extensions?: ObjMap, + data?: ObjMap | null, + extensions?: ObjMap, }; export type ExecutionArgs = { @@ -128,7 +128,7 @@ export type ExecutionArgs = { document: DocumentNode, rootValue?: mixed, contextValue?: mixed, - variableValues?: ?{ readonly [variable: string]: mixed, ... }, + variableValues?: ?{ readonly [variable: string]: unknown, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, typeResolver?: ?GraphQLTypeResolver, @@ -210,7 +210,7 @@ export function executeSync(args: ExecutionArgs): ExecutionResult { */ function buildResponse( exeContext: ExecutionContext, - data: PromiseOrValue | null>, + data: PromiseOrValue | null>, ): PromiseOrValue { if (isPromise(data)) { return data.then((resolved) => buildResponse(exeContext, resolved)); @@ -229,7 +229,7 @@ function buildResponse( export function assertValidExecutionArguments( schema: GraphQLSchema, document: DocumentNode, - rawVariableValues: ?{ readonly [variable: string]: mixed, ... }, + rawVariableValues: ?{ readonly [variable: string]: unknown, ... }, ): void { devAssert(document, 'Must provide document.'); @@ -254,12 +254,12 @@ export function assertValidExecutionArguments( export function buildExecutionContext( schema: GraphQLSchema, document: DocumentNode, - rootValue: mixed, - contextValue: mixed, - rawVariableValues: ?{ readonly [variable: string]: mixed, ... }, + rootValue: unknown, + contextValue: unknown, + rawVariableValues: ?{ readonly [variable: string]: unknown, ... }, operationName: ?string, - fieldResolver: ?GraphQLFieldResolver, - typeResolver?: ?GraphQLTypeResolver, + fieldResolver: ?GraphQLFieldResolver, + typeResolver?: ?GraphQLTypeResolver, ): ReadonlyArray | ExecutionContext { let operation: OperationDefinitionNode | void; const fragments: ObjMap = Object.create(null); @@ -325,8 +325,8 @@ export function buildExecutionContext( function executeOperation( exeContext: ExecutionContext, operation: OperationDefinitionNode, - rootValue: mixed, -): PromiseOrValue | null> { + rootValue: unknown, +): PromiseOrValue | null> { const type = getOperationRootType(exeContext.schema, operation); const fields = collectFields( exeContext, @@ -366,10 +366,10 @@ function executeOperation( function executeFieldsSerially( exeContext: ExecutionContext, parentType: GraphQLObjectType, - sourceValue: mixed, + sourceValue: unknown, path: Path | void, fields: ObjMap>, -): PromiseOrValue> { +): PromiseOrValue> { return promiseReduce( Object.keys(fields), (results, responseName) => { @@ -405,10 +405,10 @@ function executeFieldsSerially( function executeFields( exeContext: ExecutionContext, parentType: GraphQLObjectType, - sourceValue: mixed, + sourceValue: unknown, path: Path | void, fields: ObjMap>, -): PromiseOrValue> { +): PromiseOrValue> { const results = Object.create(null); let containsPromise = false; @@ -584,10 +584,10 @@ function getFieldEntryKey(node: FieldNode): string { function resolveField( exeContext: ExecutionContext, parentType: GraphQLObjectType, - source: mixed, + source: unknown, fieldNodes: ReadonlyArray, path: Path, -): PromiseOrValue { +): PromiseOrValue { const fieldNode = fieldNodes[0]; const fieldName = fieldNode.name.value; @@ -661,7 +661,7 @@ function resolveField( */ export function buildResolveInfo( exeContext: ExecutionContext, - fieldDef: GraphQLField, + fieldDef: GraphQLField, fieldNodes: ReadonlyArray, parentType: GraphQLObjectType, path: Path, @@ -726,8 +726,8 @@ function completeValue( fieldNodes: ReadonlyArray, info: GraphQLResolveInfo, path: Path, - result: mixed, -): PromiseOrValue { + result: unknown, +): PromiseOrValue { // If result is an Error, throw a located error. if (result instanceof Error) { throw result; @@ -819,8 +819,8 @@ function completeListValue( fieldNodes: ReadonlyArray, info: GraphQLResolveInfo, path: Path, - result: mixed, -): PromiseOrValue> { + result: unknown, +): PromiseOrValue> { if (!isCollection(result)) { throw new GraphQLError( `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`, @@ -886,7 +886,7 @@ function completeListValue( * Complete a Scalar or Enum by serializing to a valid value, returning * null if serialization is not possible. */ -function completeLeafValue(returnType: GraphQLLeafType, result: mixed): mixed { +function completeLeafValue(returnType: GraphQLLeafType, result: unknown): unknown { const serializedResult = returnType.serialize(result); if (serializedResult === undefined) { throw new Error( @@ -907,8 +907,8 @@ function completeAbstractValue( fieldNodes: ReadonlyArray, info: GraphQLResolveInfo, path: Path, - result: mixed, -): PromiseOrValue> { + result: unknown, +): PromiseOrValue> { const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver; const contextValue = exeContext.contextValue; const runtimeType = resolveTypeFn(result, contextValue, info, returnType); @@ -951,12 +951,12 @@ function completeAbstractValue( } function ensureValidRuntimeType( - runtimeTypeName: mixed, + runtimeTypeName: unknown, exeContext: ExecutionContext, returnType: GraphQLAbstractType, fieldNodes: ReadonlyArray, info: GraphQLResolveInfo, - result: mixed, + result: unknown, ): GraphQLObjectType { if (runtimeTypeName == null) { throw new GraphQLError( @@ -1014,8 +1014,8 @@ function completeObjectValue( fieldNodes: ReadonlyArray, info: GraphQLResolveInfo, path: Path, - result: mixed, -): PromiseOrValue> { + result: unknown, +): PromiseOrValue> { // If there is an isTypeOf predicate function, call it with the // current result. If isTypeOf returns false, then raise an error rather // than continuing execution. @@ -1053,7 +1053,7 @@ function completeObjectValue( function invalidReturnTypeError( returnType: GraphQLObjectType, - result: mixed, + result: unknown, fieldNodes: ReadonlyArray, ): GraphQLError { return new GraphQLError( @@ -1067,8 +1067,8 @@ function collectAndExecuteSubfields( returnType: GraphQLObjectType, fieldNodes: ReadonlyArray, path: Path, - result: mixed, -): PromiseOrValue> { + result: unknown, +): PromiseOrValue> { // Collect sub-fields to execute to complete this value. const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes); return executeFields(exeContext, returnType, result, path, subFieldNodes); @@ -1111,7 +1111,7 @@ function _collectSubfields( * Otherwise, test each possible type for the abstract type by calling * isTypeOf for the object being coerced, returning the first type that matches. */ -export const defaultTypeResolver: GraphQLTypeResolver = function ( +export const defaultTypeResolver: GraphQLTypeResolver = function ( value, contextValue, info, @@ -1158,8 +1158,8 @@ export const defaultTypeResolver: GraphQLTypeResolver = function ( * of calling that function while passing along args and context value. */ export const defaultFieldResolver: GraphQLFieldResolver< - mixed, - mixed, + unknown, + unknown, > = function (source: any, args, contextValue, info) { // ensure source is a value for which property access is acceptable. if (isObjectLike(source) || typeof source === 'function') { @@ -1186,7 +1186,7 @@ export function getFieldDef( schema: GraphQLSchema, parentType: GraphQLObjectType, fieldName: string, -): ?GraphQLField { +): ?GraphQLField { if ( fieldName === SchemaMetaFieldDef.name && schema.getQueryType() === parentType diff --git a/src/execution/values.ts b/src/execution/values.ts index 63f3bdbca80..3cf1c54c16d 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -24,7 +24,7 @@ import { coerceInputValue } from '../utilities/coerceInputValue'; type CoercedVariableValues = | { errors: ReadonlyArray } - | { coerced: { [variable: string]: mixed, ... } }; + | { coerced: { [variable: string]: unknown, ... } }; /** * Prepares an object map of variableValues of the correct type based on the @@ -40,7 +40,7 @@ type CoercedVariableValues = export function getVariableValues( schema: GraphQLSchema, varDefNodes: ReadonlyArray, - inputs: { readonly [variable: string]: mixed, ... }, + inputs: { readonly [variable: string]: unknown, ... }, options?: { maxErrors?: number }, ): CoercedVariableValues { const errors = []; @@ -73,9 +73,9 @@ export function getVariableValues( function coerceVariableValues( schema: GraphQLSchema, varDefNodes: ReadonlyArray, - inputs: { readonly [variable: string]: mixed, ... }, + inputs: { readonly [variable: string]: unknown, ... }, onError: (GraphQLError) => void, -): { [variable: string]: mixed, ... } { +): { [variable: string]: unknown, ... } { const coercedValues = {}; for (const varDefNode of varDefNodes) { const varName = varDefNode.variable.name.value; @@ -157,10 +157,10 @@ function coerceVariableValues( * @internal */ export function getArgumentValues( - def: GraphQLField | GraphQLDirective, + def: GraphQLField | GraphQLDirective, node: FieldNode | DirectiveNode, - variableValues?: ?ObjMap, -): { [argument: string]: mixed, ... } { + variableValues?: ?ObjMap, +): { [argument: string]: unknown, ... } { const coercedValues = {}; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') @@ -245,8 +245,8 @@ export function getArgumentValues( export function getDirectiveValues( directiveDef: GraphQLDirective, node: { +directives?: ReadonlyArray, ... }, - variableValues?: ?ObjMap, -): void | { [argument: string]: mixed, ... } { + variableValues?: ?ObjMap, +): void | { [argument: string]: unknown, ... } { // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') const directiveNode = node.directives?.find( (directive) => directive.name.value === directiveDef.name, @@ -257,6 +257,6 @@ export function getDirectiveValues( } } -function hasOwnProperty(obj: mixed, prop: string): boolean { +function hasOwnProperty(obj: unknown, prop: string): boolean { return Object.prototype.hasOwnProperty.call(obj, prop); } diff --git a/src/graphql.ts b/src/graphql.ts index a7b224c08be..4948bfc6959 100644 --- a/src/graphql.ts +++ b/src/graphql.ts @@ -58,9 +58,9 @@ import { execute } from './execution/execute'; export type GraphQLArgs = { schema: GraphQLSchema, source: string | Source, - rootValue?: mixed, - contextValue?: mixed, - variableValues?: ?{ readonly [variable: string]: mixed, ... }, + rootValue?: unknown, + contextValue?: unknown, + variableValues?: ?{ readonly [variable: string]: unknown, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, typeResolver?: ?GraphQLTypeResolver, diff --git a/src/jsutils/__tests__/inspect-test.ts b/src/jsutils/__tests__/inspect-test.ts index ba7ca9a86cb..08531f399c0 100644 --- a/src/jsutils/__tests__/inspect-test.ts +++ b/src/jsutils/__tests__/inspect-test.ts @@ -139,10 +139,10 @@ describe('inspect', () => { expect(inspect(array)).to.equal('[[Circular], [[Circular]]]'); - const mixed = { array: [] }; - mixed.array[0] = mixed; + const unknown = { array: [] }; + unknown.array[0] = unknown; - expect(inspect(mixed)).to.equal('{ array: [[Circular]] }'); + expect(inspect(unknown)).to.equal('{ array: [[Circular]] }'); const customA = { toJSON: () => customB, diff --git a/src/jsutils/devAssert.ts b/src/jsutils/devAssert.ts index da2adfcd001..f8364cee320 100644 --- a/src/jsutils/devAssert.ts +++ b/src/jsutils/devAssert.ts @@ -1,4 +1,4 @@ -export default function devAssert(condition: mixed, message: string): void { +export default function devAssert(condition: unknown, message: string): void { const booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js') if (!booleanCondition) { diff --git a/src/jsutils/inspect.ts b/src/jsutils/inspect.ts index f841f7da8d3..e0fb7195759 100644 --- a/src/jsutils/inspect.ts +++ b/src/jsutils/inspect.ts @@ -6,11 +6,11 @@ const MAX_RECURSIVE_DEPTH = 2; /** * Used to print values in error messages. */ -export default function inspect(value: mixed): string { +export default function inspect(value: unknown): string { return formatValue(value, []); } -function formatValue(value: mixed, seenValues: Array): string { +function formatValue(value: unknown, seenValues: Array): string { switch (typeof value) { case 'string': return JSON.stringify(value); @@ -28,7 +28,7 @@ function formatValue(value: mixed, seenValues: Array): string { function formatObjectValue( value: Object, - previouslySeenValues: Array, + previouslySeenValues: Array, ): string { if (previouslySeenValues.indexOf(value) !== -1) { return '[Circular]'; @@ -52,7 +52,7 @@ function formatObjectValue( return formatObject(value, seenValues); } -function formatObject(object: Object, seenValues: Array): string { +function formatObject(object: Object, seenValues: Array): string { const keys = Object.keys(object); if (keys.length === 0) { return '{}'; @@ -70,7 +70,7 @@ function formatObject(object: Object, seenValues: Array): string { return '{ ' + properties.join(', ') + ' }'; } -function formatArray(array: Array, seenValues: Array): string { +function formatArray(array: Array, seenValues: Array): string { if (array.length === 0) { return '[]'; } diff --git a/src/jsutils/instanceOf.ts b/src/jsutils/instanceOf.ts index e55cd13f730..47448c35f23 100644 --- a/src/jsutils/instanceOf.ts +++ b/src/jsutils/instanceOf.ts @@ -3,8 +3,8 @@ * constructors are detected. */ declare function instanceOf( - value: mixed, - constructor: mixed, + value: unknown, + constructor: unknown, ): boolean %checks(value instanceof constructor); // See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production @@ -12,7 +12,7 @@ declare function instanceOf( export default process.env.NODE_ENV === 'production' ? // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317') // eslint-disable-next-line no-shadow - function instanceOf(value: mixed, constructor: mixed): boolean { + function instanceOf(value: unknown, constructor: unknown): boolean { return value instanceof constructor; } : // eslint-disable-next-line no-shadow diff --git a/src/jsutils/invariant.ts b/src/jsutils/invariant.ts index 668f6ea426b..ea99078976d 100644 --- a/src/jsutils/invariant.ts +++ b/src/jsutils/invariant.ts @@ -1,4 +1,4 @@ -export default function invariant(condition: mixed, message?: string): void { +export default function invariant(condition: unknown, message?: string): void { const booleanCondition = Boolean(condition); // istanbul ignore else (See transformation done in './resources/inlineInvariant.js') if (!booleanCondition) { diff --git a/src/jsutils/isAsyncIterable.ts b/src/jsutils/isAsyncIterable.ts index 39a90bd3468..bdc8d1b6915 100644 --- a/src/jsutils/isAsyncIterable.ts +++ b/src/jsutils/isAsyncIterable.ts @@ -2,7 +2,7 @@ * Returns true if the provided object implements the AsyncIterator protocol via * either implementing a `Symbol.asyncIterator` or `"@@asyncIterator"` method. */ -declare function isAsyncIterable(value: mixed): boolean %checks(value instanceof +declare function isAsyncIterable(value: unknown): boolean %checks(value instanceof AsyncIterable); // eslint-disable-next-line no-redeclare diff --git a/src/jsutils/isCollection.ts b/src/jsutils/isCollection.ts index b120bda73d4..bc2a96886d4 100644 --- a/src/jsutils/isCollection.ts +++ b/src/jsutils/isCollection.ts @@ -19,7 +19,7 @@ * An Object value which might implement the Iterable or Array-like protocols. * @return {boolean} true if Iterable or Array-like Object. */ -declare function isCollection(value: mixed): boolean %checks(value instanceof +declare function isCollection(value: unknown): boolean %checks(value instanceof Iterable); // eslint-disable-next-line no-redeclare diff --git a/src/jsutils/isObjectLike.ts b/src/jsutils/isObjectLike.ts index a5f9754dd78..97c5f53a669 100644 --- a/src/jsutils/isObjectLike.ts +++ b/src/jsutils/isObjectLike.ts @@ -2,6 +2,6 @@ * Return true if `value` is object-like. A value is object-like if it's not * `null` and has a `typeof` result of "object". */ -export default function isObjectLike(value: mixed): boolean %checks { +export default function isObjectLike(value: unknown): boolean %checks { return typeof value == 'object' && value !== null; } diff --git a/src/jsutils/isPromise.ts b/src/jsutils/isPromise.ts index 4bbb5768e18..c1908decde7 100644 --- a/src/jsutils/isPromise.ts +++ b/src/jsutils/isPromise.ts @@ -2,7 +2,7 @@ * Returns true if the value acts like a Promise, i.e. has a "then" function, * otherwise returns false. */ -declare function isPromise(value: mixed): boolean %checks(value instanceof +declare function isPromise(value: unknown): boolean %checks(value instanceof Promise); // eslint-disable-next-line no-redeclare diff --git a/src/jsutils/memoize3.ts b/src/jsutils/memoize3.ts index c243b505742..841301a6f92 100644 --- a/src/jsutils/memoize3.ts +++ b/src/jsutils/memoize3.ts @@ -2,10 +2,10 @@ * Memoizes the provided three-argument function. */ export default function memoize3< - A1: { ... } | ReadonlyArray, - A2: { ... } | ReadonlyArray, - A3: { ... } | ReadonlyArray, - R: mixed, + A1: { ... } | ReadonlyArray, + A2: { ... } | ReadonlyArray, + A3: { ... } | ReadonlyArray, + R: unknown, >(fn: (A1, A2, A3) => R): (A1, A2, A3) => R { let cache0; diff --git a/src/language/__tests__/schema-parser-test.ts b/src/language/__tests__/schema-parser-test.ts index 2e6ffbd7454..fa989fda417 100644 --- a/src/language/__tests__/schema-parser-test.ts +++ b/src/language/__tests__/schema-parser-test.ts @@ -12,7 +12,7 @@ function expectSyntaxError(text: string) { return expect(() => parse(text)).to.throw(); } -function typeNode(name: mixed, loc: mixed) { +function typeNode(name: unknown, loc: unknown) { return { kind: 'NamedType', name: nameNode(name, loc), @@ -20,7 +20,7 @@ function typeNode(name: mixed, loc: mixed) { }; } -function nameNode(name: mixed, loc: mixed) { +function nameNode(name: unknown, loc: unknown) { return { kind: 'Name', value: name, @@ -28,11 +28,11 @@ function nameNode(name: mixed, loc: mixed) { }; } -function fieldNode(name: mixed, type: mixed, loc: mixed) { +function fieldNode(name: unknown, type: unknown, loc: unknown) { return fieldNodeWithArgs(name, type, [], loc); } -function fieldNodeWithArgs(name: mixed, type: mixed, args: mixed, loc: mixed) { +function fieldNodeWithArgs(name: unknown, type: unknown, args: unknown, loc: unknown) { return { kind: 'FieldDefinition', description: undefined, @@ -44,7 +44,7 @@ function fieldNodeWithArgs(name: mixed, type: mixed, args: mixed, loc: mixed) { }; } -function enumValueNode(name: mixed, loc: mixed) { +function enumValueNode(name: unknown, loc: unknown) { return { kind: 'EnumValueDefinition', name: nameNode(name, loc), @@ -55,10 +55,10 @@ function enumValueNode(name: mixed, loc: mixed) { } function inputValueNode( - name: mixed, - type: mixed, - defaultValue: mixed, - loc: mixed, + name: unknown, + type: unknown, + defaultValue: unknown, + loc: unknown, ) { return { kind: 'InputValueDefinition', diff --git a/src/language/__tests__/toJSONDeep.ts b/src/language/__tests__/toJSONDeep.ts index 3c3fae57f3e..9c84554ce8f 100644 --- a/src/language/__tests__/toJSONDeep.ts +++ b/src/language/__tests__/toJSONDeep.ts @@ -4,7 +4,7 @@ import isObjectLike from '../../jsutils/isObjectLike'; * Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON * on any nested value which defines it. */ -export default function toJSONDeep(value: mixed): mixed { +export default function toJSONDeep(value: unknown): unknown { if (!isObjectLike(value)) { return value; } diff --git a/src/language/ast.ts b/src/language/ast.ts index a81f1743371..213e1ab72c9 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -45,7 +45,7 @@ export class Location { // @deprecated: Will be removed in v17 // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet - [Symbol.for('nodejs.util.inspect.custom')](): mixed { + [Symbol.for('nodejs.util.inspect.custom')](): unknown { return this.toJSON(); } } @@ -128,7 +128,7 @@ export class Token { // @deprecated: Will be removed in v17 // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet - [Symbol.for('nodejs.util.inspect.custom')](): mixed { + [Symbol.for('nodejs.util.inspect.custom')](): unknown { return this.toJSON(); } } @@ -136,7 +136,7 @@ export class Token { /** * @internal */ -export function isNode(maybeNode: mixed): boolean %checks { +export function isNode(maybeNode: unknown): boolean %checks { return maybeNode != null && typeof maybeNode.kind === 'string'; } diff --git a/src/language/source.ts b/src/language/source.ts index 53fa68d8524..235d59708d8 100644 --- a/src/language/source.ts +++ b/src/language/source.ts @@ -53,7 +53,7 @@ export class Source { * * @internal */ -declare function isSource(source: mixed): boolean %checks(source instanceof +declare function isSource(source: unknown): boolean %checks(source instanceof Source); // eslint-disable-next-line no-redeclare export function isSource(source) { diff --git a/src/subscription/__tests__/simplePubSub.ts b/src/subscription/__tests__/simplePubSub.ts index e12c93d0b9d..6fe4080e64f 100644 --- a/src/subscription/__tests__/simplePubSub.ts +++ b/src/subscription/__tests__/simplePubSub.ts @@ -49,7 +49,7 @@ export default class SimplePubSub { emptyQueue(); return Promise.resolve({ value: undefined, done: true }); }, - throw(error: mixed) { + throw(error: unknown) { emptyQueue(); return Promise.reject(error); }, diff --git a/src/subscription/__tests__/subscribe-test.ts b/src/subscription/__tests__/subscribe-test.ts index 082d78d45a8..c6917a9329d 100644 --- a/src/subscription/__tests__/subscribe-test.ts +++ b/src/subscription/__tests__/subscribe-test.ts @@ -68,9 +68,9 @@ const EmailEventType = new GraphQLObjectType({ const emailSchema = emailSchemaWithResolvers(); -function emailSchemaWithResolvers( - subscribeFn?: (T) => mixed, - resolveFn?: (T) => mixed, +function emailSchemaWithResolvers( + subscribeFn?: (T) => unknown, + resolveFn?: (T) => unknown, ) { return new GraphQLSchema({ query: QueryType, @@ -137,7 +137,7 @@ function createSubscription( } async function expectPromiseToThrow( - promise: () => Promise, + promise: () => Promise, message: string, ) { try { diff --git a/src/subscription/mapAsyncIterator.ts b/src/subscription/mapAsyncIterator.ts index 5a64de54f1c..c170dad6f22 100644 --- a/src/subscription/mapAsyncIterator.ts +++ b/src/subscription/mapAsyncIterator.ts @@ -16,7 +16,7 @@ export default function mapAsyncIterator( let abruptClose; if (typeof iterator.return === 'function') { $return = iterator.return; - abruptClose = (error: mixed) => { + abruptClose = (error: unknown) => { const rethrow = () => Promise.reject(error); return $return.call(iterator).then(rethrow, rethrow); }; @@ -32,7 +32,7 @@ export default function mapAsyncIterator( if (rejectCallback) { // Capture rejectCallback to ensure it cannot be null. const reject = rejectCallback; - mapReject = (error: mixed) => + mapReject = (error: unknown) => asyncMapValue(error, reject).then(iteratorResult, abruptClose); } @@ -47,7 +47,7 @@ export default function mapAsyncIterator( ? $return.call(iterator).then(mapResult, mapReject) : Promise.resolve({ value: undefined, done: true }); }, - throw(error?: mixed): Promise> { + throw(error?: unknown): Promise> { if (typeof iterator.throw === 'function') { return iterator.throw(error).then(mapResult, mapReject); } diff --git a/src/subscription/subscribe.ts b/src/subscription/subscribe.ts index 631c2997009..53d77596a9d 100644 --- a/src/subscription/subscribe.ts +++ b/src/subscription/subscribe.ts @@ -28,9 +28,9 @@ import mapAsyncIterator from './mapAsyncIterator'; export type SubscriptionArgs = { schema: GraphQLSchema, document: DocumentNode, - rootValue?: mixed, - contextValue?: mixed, - variableValues?: ?{ readonly [variable: string]: mixed, ... }, + rootValue?: unknown, + contextValue?: unknown, + variableValues?: ?{ readonly [variable: string]: unknown, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, subscribeFieldResolver?: ?GraphQLFieldResolver, @@ -117,7 +117,7 @@ export function subscribe( * an ExecutionResult, containing only errors and no data. Otherwise treat the * error as a system-class error and re-throw it. */ -function reportGraphQLError(error: mixed): ExecutionResult { +function reportGraphQLError(error: unknown): ExecutionResult { if (error instanceof GraphQLError) { return { errors: [error] }; } @@ -155,12 +155,12 @@ function reportGraphQLError(error: mixed): ExecutionResult { export function createSourceEventStream( schema: GraphQLSchema, document: DocumentNode, - rootValue?: mixed, - contextValue?: mixed, - variableValues?: ?{ readonly [variable: string]: mixed, ... }, + rootValue?: unknown, + contextValue?: unknown, + variableValues?: ?{ readonly [variable: string]: unknown, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, -): Promise | ExecutionResult> { +): Promise | ExecutionResult> { // If arguments are missing or incorrectly typed, this is an internal // developer mistake which should throw an early error. assertValidExecutionArguments(schema, document, variableValues); @@ -189,7 +189,7 @@ export function createSourceEventStream( function executeSubscription( exeContext: ExecutionContext, -): Promise> { +): Promise> { const { schema, operation, variableValues, rootValue } = exeContext; const type = getOperationRootType(schema, operation); const fields = collectFields( diff --git a/src/type/__tests__/definition-test.ts b/src/type/__tests__/definition-test.ts index 65b176d150f..1e97a6d33ba 100644 --- a/src/type/__tests__/definition-test.ts +++ b/src/type/__tests__/definition-test.ts @@ -922,7 +922,7 @@ describe('Type System: test utility methods', () => { }); it('Object.toStringifies types', () => { - function toString(obj: mixed): string { + function toString(obj: unknown): string { return Object.prototype.toString.call(obj); } diff --git a/src/type/__tests__/enumType-test.ts b/src/type/__tests__/enumType-test.ts index 4d232794469..d4a5cc2753e 100644 --- a/src/type/__tests__/enumType-test.ts +++ b/src/type/__tests__/enumType-test.ts @@ -114,7 +114,7 @@ const schema = new GraphQLSchema({ function executeQuery( source: string, - variableValues?: { readonly [variable: string]: mixed, ... }, + variableValues?: { readonly [variable: string]: unknown, ... }, ) { return graphqlSync({ schema, source, variableValues }); } diff --git a/src/type/__tests__/extensions-test.ts b/src/type/__tests__/extensions-test.ts index 76dd0ee233e..792e962b7d9 100644 --- a/src/type/__tests__/extensions-test.ts +++ b/src/type/__tests__/extensions-test.ts @@ -16,7 +16,7 @@ import { const dummyType = new GraphQLScalarType({ name: 'DummyScalar' }); -function expectObjMap(value: mixed) { +function expectObjMap(value: unknown) { invariant(value != null && typeof value === 'object'); expect(Object.getPrototypeOf(value)).to.equal(null); return expect(value); diff --git a/src/type/__tests__/predicate-test.ts b/src/type/__tests__/predicate-test.ts index 33c2c49f579..f9d189c6f57 100644 --- a/src/type/__tests__/predicate-test.ts +++ b/src/type/__tests__/predicate-test.ts @@ -296,7 +296,7 @@ describe('Type predicates', () => { }); describe('isInputType', () => { - function expectInputType(type: mixed) { + function expectInputType(type: unknown) { expect(isInputType(type)).to.equal(true); expect(() => assertInputType(type)).to.not.throw(); } @@ -317,7 +317,7 @@ describe('Type predicates', () => { expectInputType(new GraphQLNonNull(InputObjectType)); }); - function expectNonInputType(type: mixed) { + function expectNonInputType(type: unknown) { expect(isInputType(type)).to.equal(false); expect(() => assertInputType(type)).to.throw(); } @@ -340,7 +340,7 @@ describe('Type predicates', () => { }); describe('isOutputType', () => { - function expectOutputType(type: mixed) { + function expectOutputType(type: unknown) { expect(isOutputType(type)).to.equal(true); expect(() => assertOutputType(type)).to.not.throw(); } @@ -367,7 +367,7 @@ describe('Type predicates', () => { expectOutputType(new GraphQLNonNull(EnumType)); }); - function expectNonOutputType(type: mixed) { + function expectNonOutputType(type: unknown) { expect(isOutputType(type)).to.equal(false); expect(() => assertOutputType(type)).to.throw(); } diff --git a/src/type/__tests__/scalars-test.ts b/src/type/__tests__/scalars-test.ts index 6e901c3fb05..67b1610c28f 100644 --- a/src/type/__tests__/scalars-test.ts +++ b/src/type/__tests__/scalars-test.ts @@ -14,7 +14,7 @@ import { describe('Type System: Specified scalar types', () => { describe('GraphQLInt', () => { it('parseValue', () => { - function parseValue(value: mixed) { + function parseValue(value: unknown) { return GraphQLInt.parseValue(value); } @@ -110,7 +110,7 @@ describe('Type System: Specified scalar types', () => { }); it('serialize', () => { - function serialize(value: mixed) { + function serialize(value: unknown) { return GraphQLInt.serialize(value); } @@ -183,7 +183,7 @@ describe('Type System: Specified scalar types', () => { describe('GraphQLFloat', () => { it('parseValue', () => { - function parseValue(value: mixed) { + function parseValue(value: unknown) { return GraphQLFloat.parseValue(value); } @@ -270,7 +270,7 @@ describe('Type System: Specified scalar types', () => { }); it('serialize', () => { - function serialize(value: mixed) { + function serialize(value: unknown) { return GraphQLFloat.serialize(value); } @@ -313,7 +313,7 @@ describe('Type System: Specified scalar types', () => { describe('GraphQLString', () => { it('parseValue', () => { - function parseValue(value: mixed) { + function parseValue(value: unknown) { return GraphQLString.parseValue(value); } @@ -377,7 +377,7 @@ describe('Type System: Specified scalar types', () => { }); it('serialize', () => { - function serialize(value: mixed) { + function serialize(value: unknown) { return GraphQLString.serialize(value); } @@ -418,7 +418,7 @@ describe('Type System: Specified scalar types', () => { describe('GraphQLBoolean', () => { it('parseValue', () => { - function parseValue(value: mixed) { + function parseValue(value: unknown) { return GraphQLBoolean.parseValue(value); } @@ -495,7 +495,7 @@ describe('Type System: Specified scalar types', () => { }); it('serialize', () => { - function serialize(value: mixed) { + function serialize(value: unknown) { return GraphQLBoolean.serialize(value); } @@ -532,7 +532,7 @@ describe('Type System: Specified scalar types', () => { describe('GraphQLID', () => { it('parseValue', () => { - function parseValue(value: mixed) { + function parseValue(value: unknown) { return GraphQLID.parseValue(value); } @@ -610,7 +610,7 @@ describe('Type System: Specified scalar types', () => { }); it('serialize', () => { - function serialize(value: mixed) { + function serialize(value: unknown) { return GraphQLID.serialize(value); } diff --git a/src/type/__tests__/validation-test.ts b/src/type/__tests__/validation-test.ts index a3e35443dad..5316d68d4cf 100644 --- a/src/type/__tests__/validation-test.ts +++ b/src/type/__tests__/validation-test.ts @@ -1007,7 +1007,7 @@ describe('Type System: Enum types must be well defined', () => { describe('Type System: Object fields must have output types', () => { function schemaWithObjectField( - fieldConfig: GraphQLFieldConfig, + fieldConfig: GraphQLFieldConfig, ): GraphQLSchema { const BadObjectType = new GraphQLObjectType({ name: 'BadObject', @@ -1322,7 +1322,7 @@ describe('Type System: Interface extensions should be valid', () => { describe('Type System: Interface fields must have output types', () => { function schemaWithInterfaceField( - fieldConfig: GraphQLFieldConfig, + fieldConfig: GraphQLFieldConfig, ): GraphQLSchema { const fields = { badField: fieldConfig }; diff --git a/src/type/definition.ts b/src/type/definition.ts index 8ae0576927b..b7f9bb10eda 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -64,7 +64,7 @@ export type GraphQLType = | GraphQLList | GraphQLNonNull; -export function isType(type: mixed): boolean %checks { +export function isType(type: unknown): boolean %checks { return ( isScalarType(type) || isObjectType(type) || @@ -77,7 +77,7 @@ export function isType(type: mixed): boolean %checks { ); } -export function assertType(type: mixed): GraphQLType { +export function assertType(type: unknown): GraphQLType { if (!isType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL type.`); } @@ -88,42 +88,42 @@ export function assertType(type: mixed): GraphQLType { * There are predicates for each kind of GraphQL type. */ -declare function isScalarType(type: mixed): boolean %checks(type instanceof +declare function isScalarType(type: unknown): boolean %checks(type instanceof GraphQLScalarType); // eslint-disable-next-line no-redeclare export function isScalarType(type) { return instanceOf(type, GraphQLScalarType); } -export function assertScalarType(type: mixed): GraphQLScalarType { +export function assertScalarType(type: unknown): GraphQLScalarType { if (!isScalarType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL Scalar type.`); } return type; } -declare function isObjectType(type: mixed): boolean %checks(type instanceof +declare function isObjectType(type: unknown): boolean %checks(type instanceof GraphQLObjectType); // eslint-disable-next-line no-redeclare export function isObjectType(type) { return instanceOf(type, GraphQLObjectType); } -export function assertObjectType(type: mixed): GraphQLObjectType { +export function assertObjectType(type: unknown): GraphQLObjectType { if (!isObjectType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL Object type.`); } return type; } -declare function isInterfaceType(type: mixed): boolean %checks(type instanceof +declare function isInterfaceType(type: unknown): boolean %checks(type instanceof GraphQLInterfaceType); // eslint-disable-next-line no-redeclare export function isInterfaceType(type) { return instanceOf(type, GraphQLInterfaceType); } -export function assertInterfaceType(type: mixed): GraphQLInterfaceType { +export function assertInterfaceType(type: unknown): GraphQLInterfaceType { if (!isInterfaceType(type)) { throw new Error( `Expected ${inspect(type)} to be a GraphQL Interface type.`, @@ -132,42 +132,42 @@ export function assertInterfaceType(type: mixed): GraphQLInterfaceType { return type; } -declare function isUnionType(type: mixed): boolean %checks(type instanceof +declare function isUnionType(type: unknown): boolean %checks(type instanceof GraphQLUnionType); // eslint-disable-next-line no-redeclare export function isUnionType(type) { return instanceOf(type, GraphQLUnionType); } -export function assertUnionType(type: mixed): GraphQLUnionType { +export function assertUnionType(type: unknown): GraphQLUnionType { if (!isUnionType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL Union type.`); } return type; } -declare function isEnumType(type: mixed): boolean %checks(type instanceof +declare function isEnumType(type: unknown): boolean %checks(type instanceof GraphQLEnumType); // eslint-disable-next-line no-redeclare export function isEnumType(type) { return instanceOf(type, GraphQLEnumType); } -export function assertEnumType(type: mixed): GraphQLEnumType { +export function assertEnumType(type: unknown): GraphQLEnumType { if (!isEnumType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL Enum type.`); } return type; } -declare function isInputObjectType(type: mixed): boolean %checks(type instanceof +declare function isInputObjectType(type: unknown): boolean %checks(type instanceof GraphQLInputObjectType); // eslint-disable-next-line no-redeclare export function isInputObjectType(type) { return instanceOf(type, GraphQLInputObjectType); } -export function assertInputObjectType(type: mixed): GraphQLInputObjectType { +export function assertInputObjectType(type: unknown): GraphQLInputObjectType { if (!isInputObjectType(type)) { throw new Error( `Expected ${inspect(type)} to be a GraphQL Input Object type.`, @@ -176,28 +176,28 @@ export function assertInputObjectType(type: mixed): GraphQLInputObjectType { return type; } -declare function isListType(type: mixed): boolean %checks(type instanceof +declare function isListType(type: unknown): boolean %checks(type instanceof GraphQLList); // eslint-disable-next-line no-redeclare export function isListType(type) { return instanceOf(type, GraphQLList); } -export function assertListType(type: mixed): GraphQLList { +export function assertListType(type: unknown): GraphQLList { if (!isListType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL List type.`); } return type; } -declare function isNonNullType(type: mixed): boolean %checks(type instanceof +declare function isNonNullType(type: unknown): boolean %checks(type instanceof GraphQLNonNull); // eslint-disable-next-line no-redeclare export function isNonNullType(type) { return instanceOf(type, GraphQLNonNull); } -export function assertNonNullType(type: mixed): GraphQLNonNull { +export function assertNonNullType(type: unknown): GraphQLNonNull { if (!isNonNullType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL Non-Null type.`); } @@ -219,7 +219,7 @@ export type GraphQLInputType = | GraphQLList, >; -export function isInputType(type: mixed): boolean %checks { +export function isInputType(type: unknown): boolean %checks { return ( isScalarType(type) || isEnumType(type) || @@ -228,7 +228,7 @@ export function isInputType(type: mixed): boolean %checks { ); } -export function assertInputType(type: mixed): GraphQLInputType { +export function assertInputType(type: unknown): GraphQLInputType { if (!isInputType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL input type.`); } @@ -254,7 +254,7 @@ export type GraphQLOutputType = | GraphQLList, >; -export function isOutputType(type: mixed): boolean %checks { +export function isOutputType(type: unknown): boolean %checks { return ( isScalarType(type) || isObjectType(type) || @@ -265,7 +265,7 @@ export function isOutputType(type: mixed): boolean %checks { ); } -export function assertOutputType(type: mixed): GraphQLOutputType { +export function assertOutputType(type: unknown): GraphQLOutputType { if (!isOutputType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL output type.`); } @@ -277,11 +277,11 @@ export function assertOutputType(type: mixed): GraphQLOutputType { */ export type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType; -export function isLeafType(type: mixed): boolean %checks { +export function isLeafType(type: unknown): boolean %checks { return isScalarType(type) || isEnumType(type); } -export function assertLeafType(type: mixed): GraphQLLeafType { +export function assertLeafType(type: unknown): GraphQLLeafType { if (!isLeafType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL leaf type.`); } @@ -296,11 +296,11 @@ export type GraphQLCompositeType = | GraphQLInterfaceType | GraphQLUnionType; -export function isCompositeType(type: mixed): boolean %checks { +export function isCompositeType(type: unknown): boolean %checks { return isObjectType(type) || isInterfaceType(type) || isUnionType(type); } -export function assertCompositeType(type: mixed): GraphQLCompositeType { +export function assertCompositeType(type: unknown): GraphQLCompositeType { if (!isCompositeType(type)) { throw new Error( `Expected ${inspect(type)} to be a GraphQL composite type.`, @@ -314,11 +314,11 @@ export function assertCompositeType(type: mixed): GraphQLCompositeType { */ export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType; -export function isAbstractType(type: mixed): boolean %checks { +export function isAbstractType(type: unknown): boolean %checks { return isInterfaceType(type) || isUnionType(type); } -export function assertAbstractType(type: mixed): GraphQLAbstractType { +export function assertAbstractType(type: unknown): GraphQLAbstractType { if (!isAbstractType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL abstract type.`); } @@ -421,11 +421,11 @@ export class GraphQLNonNull<+T: GraphQLNullableType> { export type GraphQLWrappingType = GraphQLList | GraphQLNonNull; -export function isWrappingType(type: mixed): boolean %checks { +export function isWrappingType(type: unknown): boolean %checks { return isListType(type) || isNonNullType(type); } -export function assertWrappingType(type: mixed): GraphQLWrappingType { +export function assertWrappingType(type: unknown): GraphQLWrappingType { if (!isWrappingType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL wrapping type.`); } @@ -444,11 +444,11 @@ export type GraphQLNullableType = | GraphQLInputObjectType | GraphQLList; -export function isNullableType(type: mixed): boolean %checks { +export function isNullableType(type: unknown): boolean %checks { return isType(type) && !isNonNullType(type); } -export function assertNullableType(type: mixed): GraphQLNullableType { +export function assertNullableType(type: unknown): GraphQLNullableType { if (!isNullableType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL nullable type.`); } @@ -477,7 +477,7 @@ export type GraphQLNamedType = | GraphQLEnumType | GraphQLInputObjectType; -export function isNamedType(type: mixed): boolean %checks { +export function isNamedType(type: unknown): boolean %checks { return ( isScalarType(type) || isObjectType(type) || @@ -488,7 +488,7 @@ export function isNamedType(type: mixed): boolean %checks { ); } -export function assertNamedType(type: mixed): GraphQLNamedType { +export function assertNamedType(type: unknown): GraphQLNamedType { if (!isNamedType(type)) { throw new Error(`Expected ${inspect(type)} to be a GraphQL named type.`); } @@ -552,14 +552,14 @@ export class GraphQLScalarType { name: string; description: ?string; specifiedByUrl: ?string; - serialize: GraphQLScalarSerializer; - parseValue: GraphQLScalarValueParser; - parseLiteral: GraphQLScalarLiteralParser; - extensions: ?ReadOnlyObjMap; + serialize: GraphQLScalarSerializer; + parseValue: GraphQLScalarValueParser; + parseLiteral: GraphQLScalarLiteralParser; + extensions: ?ReadOnlyObjMap; astNode: ?ScalarTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; - constructor(config: $ReadOnly>): void { + constructor(config: $ReadOnly>): void { const parseValue = config.parseValue ?? identityFunc; this.name = config.name; this.description = config.description; @@ -597,11 +597,11 @@ export class GraphQLScalarType { } toConfig(): { - ...GraphQLScalarTypeConfig, - serialize: GraphQLScalarSerializer, - parseValue: GraphQLScalarValueParser, - parseLiteral: GraphQLScalarLiteralParser, - extensions: ?ReadOnlyObjMap, + ...GraphQLScalarTypeConfig, + serialize: GraphQLScalarSerializer, + parseValue: GraphQLScalarValueParser, + parseLiteral: GraphQLScalarLiteralParser, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { return { @@ -632,16 +632,16 @@ export class GraphQLScalarType { } export type GraphQLScalarSerializer = ( - outputValue: mixed, + outputValue: unknown, ) => ?TExternal; export type GraphQLScalarValueParser = ( - inputValue: mixed, + inputValue: unknown, ) => ?TInternal; export type GraphQLScalarLiteralParser = ( valueNode: ValueNode, - variables: ?ObjMap, + variables: ?ObjMap, ) => ?TInternal; export type GraphQLScalarTypeConfig = { @@ -654,7 +654,7 @@ export type GraphQLScalarTypeConfig = { parseValue?: GraphQLScalarValueParser, // Parses an externally provided literal value to use as an input. parseLiteral?: GraphQLScalarLiteralParser, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?ScalarTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -700,7 +700,7 @@ export class GraphQLObjectType { name: string; description: ?string; isTypeOf: ?GraphQLIsTypeOfFn; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?ObjectTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -743,7 +743,7 @@ export class GraphQLObjectType { ...GraphQLObjectTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { return { @@ -774,8 +774,8 @@ export class GraphQLObjectType { function defineInterfaces( config: $ReadOnly< - | GraphQLObjectTypeConfig - | GraphQLInterfaceTypeConfig, + | GraphQLObjectTypeConfig + | GraphQLInterfaceTypeConfig, >, ): Array { const interfaces = resolveThunk(config.interfaces) ?? []; @@ -839,13 +839,13 @@ function defineFieldMap( }); } -function isPlainObj(obj: mixed): boolean { +function isPlainObj(obj: unknown): boolean { return isObjectLike(obj) && !Array.isArray(obj); } function fieldsToFieldsConfig( - fields: GraphQLFieldMap, -): GraphQLFieldConfigMap { + fields: GraphQLFieldMap, +): GraphQLFieldConfigMap { return mapValue(fields, (field) => ({ description: field.description, type: field.type, @@ -884,7 +884,7 @@ export type GraphQLObjectTypeConfig = { interfaces?: Thunk>, fields: Thunk>, isTypeOf?: ?GraphQLIsTypeOfFn, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?ObjectTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -914,7 +914,7 @@ export type GraphQLFieldResolver< args: TArgs, context: TContext, info: GraphQLResolveInfo, -) => mixed; +) => unknown; export type GraphQLResolveInfo = { readonly fieldName: string, @@ -924,9 +924,9 @@ export type GraphQLResolveInfo = { readonly path: Path, readonly schema: GraphQLSchema, readonly fragments: ObjMap, - readonly rootValue: mixed, + readonly rootValue: unknown, readonly operation: OperationDefinitionNode, - readonly variableValues: { [variable: string]: mixed, ... }, + readonly variableValues: { [variable: string]: unknown, ... }, }; export type GraphQLFieldConfig< @@ -940,7 +940,7 @@ export type GraphQLFieldConfig< resolve?: GraphQLFieldResolver, subscribe?: GraphQLFieldResolver, deprecationReason?: ?string, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?FieldDefinitionNode, }; @@ -949,8 +949,8 @@ export type GraphQLFieldConfigArgumentMap = ObjMap; export type GraphQLArgumentConfig = { description?: ?string, type: GraphQLInputType, - defaultValue?: mixed, - extensions?: ?ReadOnlyObjMapLike, + defaultValue?: unknown, + extensions?: ?ReadOnlyObjMapLike, deprecationReason?: ?string, astNode?: ?InputValueDefinitionNode, }; @@ -971,7 +971,7 @@ export type GraphQLField< resolve?: GraphQLFieldResolver, subscribe?: GraphQLFieldResolver, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, astNode: ?FieldDefinitionNode, }; @@ -979,9 +979,9 @@ export type GraphQLArgument = { name: string, description: ?string, type: GraphQLInputType, - defaultValue: mixed, + defaultValue: unknown, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, }; @@ -1015,7 +1015,7 @@ export class GraphQLInterfaceType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?InterfaceTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -1058,7 +1058,7 @@ export class GraphQLInterfaceType { ...GraphQLInterfaceTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { return { @@ -1098,7 +1098,7 @@ export type GraphQLInterfaceTypeConfig = { * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InterfaceTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -1130,7 +1130,7 @@ export class GraphQLUnionType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?UnionTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -1163,7 +1163,7 @@ export class GraphQLUnionType { toConfig(): { ...GraphQLUnionTypeConfig, types: Array, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { return { @@ -1192,7 +1192,7 @@ export class GraphQLUnionType { } function defineTypes( - config: $ReadOnly>, + config: $ReadOnly>, ): Array { const types = resolveThunk(config.types); devAssert( @@ -1212,7 +1212,7 @@ export type GraphQLUnionTypeConfig = { * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?UnionTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -1241,7 +1241,7 @@ export type GraphQLUnionTypeConfig = { export class GraphQLEnumType /* */ { name: string; description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?EnumTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -1273,7 +1273,7 @@ export class GraphQLEnumType /* */ { return this._nameLookup[name]; } - serialize(outputValue: mixed /* T */): ?string { + serialize(outputValue: unknown /* T */): ?string { const enumValue = this._valueLookup.get(outputValue); if (enumValue === undefined) { throw new GraphQLError( @@ -1283,7 +1283,7 @@ export class GraphQLEnumType /* */ { return enumValue.name; } - parseValue(inputValue: mixed): ?any /* T */ { + parseValue(inputValue: unknown): ?any /* T */ { if (typeof inputValue !== 'string') { const valueStr = inspect(inputValue); throw new GraphQLError( @@ -1302,7 +1302,7 @@ export class GraphQLEnumType /* */ { return enumValue.value; } - parseLiteral(valueNode: ValueNode, _variables: ?ObjMap): ?any /* T */ { + parseLiteral(valueNode: ValueNode, _variables: ?ObjMap): ?any /* T */ { // Note: variables will be resolved to a value before calling this function. if (valueNode.kind !== Kind.ENUM) { const valueStr = print(valueNode); @@ -1327,7 +1327,7 @@ export class GraphQLEnumType /* */ { toConfig(): { ...GraphQLEnumTypeConfig, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { const values = keyValMap( @@ -1405,7 +1405,7 @@ export type GraphQLEnumTypeConfig /* */ = { name: string, description?: ?string, values: GraphQLEnumValueConfigMap /* */, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?EnumTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -1416,7 +1416,7 @@ export type GraphQLEnumValueConfig /* */ = { description?: ?string, value?: any /* T */, deprecationReason?: ?string, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?EnumValueDefinitionNode, }; @@ -1425,7 +1425,7 @@ export type GraphQLEnumValue /* */ = { description: ?string, value: any /* T */, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, astNode: ?EnumValueDefinitionNode, }; @@ -1452,7 +1452,7 @@ export type GraphQLEnumValue /* */ = { export class GraphQLInputObjectType { name: string; description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?InputObjectTypeDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -1479,7 +1479,7 @@ export class GraphQLInputObjectType { toConfig(): { ...GraphQLInputObjectTypeConfig, fields: GraphQLInputFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, } { const fields = mapValue(this.getFields(), (field) => ({ @@ -1544,7 +1544,7 @@ export type GraphQLInputObjectTypeConfig = { name: string, description?: ?string, fields: Thunk, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputObjectTypeDefinitionNode, extensionASTNodes?: ?ReadonlyArray, }; @@ -1552,9 +1552,9 @@ export type GraphQLInputObjectTypeConfig = { export type GraphQLInputFieldConfig = { description?: ?string, type: GraphQLInputType, - defaultValue?: mixed, + defaultValue?: unknown, deprecationReason?: ?string, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputValueDefinitionNode, }; @@ -1564,9 +1564,9 @@ export type GraphQLInputField = { name: string, description: ?string, type: GraphQLInputType, - defaultValue: mixed, + defaultValue: unknown, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, }; diff --git a/src/type/directives.ts b/src/type/directives.ts index 243b14731cd..33c4ed34171 100644 --- a/src/type/directives.ts +++ b/src/type/directives.ts @@ -22,14 +22,14 @@ import { argsToArgsConfig, GraphQLNonNull } from './definition'; * Test if the given value is a GraphQL directive. */ declare function isDirective( - directive: mixed, + directive: unknown, ): boolean %checks(directive instanceof GraphQLDirective); // eslint-disable-next-line no-redeclare export function isDirective(directive) { return instanceOf(directive, GraphQLDirective); } -export function assertDirective(directive: mixed): GraphQLDirective { +export function assertDirective(directive: unknown): GraphQLDirective { if (!isDirective(directive)) { throw new Error( `Expected ${inspect(directive)} to be a GraphQL directive.`, @@ -48,7 +48,7 @@ export class GraphQLDirective { locations: Array; args: Array; isRepeatable: boolean; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?DirectiveDefinitionNode; constructor(config: $ReadOnly): void { @@ -86,7 +86,7 @@ export class GraphQLDirective { ...GraphQLDirectiveConfig, args: GraphQLFieldConfigArgumentMap, isRepeatable: boolean, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, } { return { name: this.name, @@ -119,7 +119,7 @@ export type GraphQLDirectiveConfig = { locations: Array, args?: ?GraphQLFieldConfigArgumentMap, isRepeatable?: ?boolean, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?DirectiveDefinitionNode, }; diff --git a/src/type/introspection.ts b/src/type/introspection.ts index 4963bd96746..96576e7a6ed 100644 --- a/src/type/introspection.ts +++ b/src/type/introspection.ts @@ -75,7 +75,7 @@ export const __Schema = new GraphQLObjectType({ ), resolve: (schema) => schema.getDirectives(), }, - }: GraphQLFieldConfigMap), + }: GraphQLFieldConfigMap), }); export const __Directive = new GraphQLObjectType({ @@ -108,7 +108,7 @@ export const __Directive = new GraphQLObjectType({ ), resolve: (directive) => directive.args, }, - }: GraphQLFieldConfigMap), + }: GraphQLFieldConfigMap), }); export const __DirectiveLocation = new GraphQLEnumType({ @@ -314,7 +314,7 @@ export const __Type = new GraphQLObjectType({ resolve: (type) => type.ofType !== undefined ? type.ofType : undefined, }, - }: GraphQLFieldConfigMap), + }: GraphQLFieldConfigMap), }); export const __Field = new GraphQLObjectType({ @@ -359,7 +359,7 @@ export const __Field = new GraphQLObjectType({ type: GraphQLString, resolve: (field) => field.deprecationReason, }, - }: GraphQLFieldConfigMap, mixed>), + }: GraphQLFieldConfigMap, unknown>), }); export const __InputValue = new GraphQLObjectType({ @@ -398,7 +398,7 @@ export const __InputValue = new GraphQLObjectType({ type: GraphQLString, resolve: (obj) => obj.deprecationReason, }, - }: GraphQLFieldConfigMap), + }: GraphQLFieldConfigMap), }); export const __EnumValue = new GraphQLObjectType({ @@ -423,7 +423,7 @@ export const __EnumValue = new GraphQLObjectType({ type: GraphQLString, resolve: (enumValue) => enumValue.deprecationReason, }, - }: GraphQLFieldConfigMap), + }: GraphQLFieldConfigMap), }); export const TypeKind = Object.freeze({ @@ -487,7 +487,7 @@ export const __TypeKind = new GraphQLEnumType({ * so the format for args is different. */ -export const SchemaMetaFieldDef: GraphQLField = { +export const SchemaMetaFieldDef: GraphQLField = { name: '__schema', type: new GraphQLNonNull(__Schema), description: 'Access the current type schema of this server.', @@ -498,7 +498,7 @@ export const SchemaMetaFieldDef: GraphQLField = { astNode: undefined, }; -export const TypeMetaFieldDef: GraphQLField = { +export const TypeMetaFieldDef: GraphQLField = { name: '__type', type: __Type, description: 'Request the type information of a single type.', @@ -519,7 +519,7 @@ export const TypeMetaFieldDef: GraphQLField = { astNode: undefined, }; -export const TypeNameMetaFieldDef: GraphQLField = { +export const TypeNameMetaFieldDef: GraphQLField = { name: '__typename', type: new GraphQLNonNull(GraphQLString), description: 'The name of the current Object type at runtime.', diff --git a/src/type/scalars.ts b/src/type/scalars.ts index e02d2e5c6c1..ab26d5d8112 100644 --- a/src/type/scalars.ts +++ b/src/type/scalars.ts @@ -17,7 +17,7 @@ import { GraphQLScalarType } from './definition'; const MAX_INT = 2147483647; const MIN_INT = -2147483648; -function serializeInt(outputValue: mixed): number { +function serializeInt(outputValue: unknown): number { const coercedValue = serializeObject(outputValue); if (typeof coercedValue === 'boolean') { @@ -43,7 +43,7 @@ function serializeInt(outputValue: mixed): number { return num; } -function coerceInt(inputValue: mixed): number { +function coerceInt(inputValue: unknown): number { if (typeof inputValue !== 'number' || !Number.isInteger(inputValue)) { throw new GraphQLError( `Int cannot represent non-integer value: ${inspect(inputValue)}`, @@ -81,7 +81,7 @@ export const GraphQLInt = new GraphQLScalarType({ }, }); -function serializeFloat(outputValue: mixed): number { +function serializeFloat(outputValue: unknown): number { const coercedValue = serializeObject(outputValue); if (typeof coercedValue === 'boolean') { @@ -101,7 +101,7 @@ function serializeFloat(outputValue: mixed): number { return num; } -function coerceFloat(inputValue: mixed): number { +function coerceFloat(inputValue: unknown): number { if (typeof inputValue !== 'number' || !Number.isFinite(inputValue)) { throw new GraphQLError( `Float cannot represent non numeric value: ${inspect(inputValue)}`, @@ -130,7 +130,7 @@ export const GraphQLFloat = new GraphQLScalarType({ // Support serializing objects with custom valueOf() or toJSON() functions - // a common way to represent a complex value which can be represented as // a string (ex: MongoDB id objects). -function serializeObject(outputValue: mixed): mixed { +function serializeObject(outputValue: unknown): unknown { if (isObjectLike(outputValue)) { if (typeof outputValue.valueOf === 'function') { const valueOfResult = outputValue.valueOf(); @@ -146,7 +146,7 @@ function serializeObject(outputValue: mixed): mixed { return outputValue; } -function serializeString(outputValue: mixed): string { +function serializeString(outputValue: unknown): string { const coercedValue = serializeObject(outputValue); // Serialize string, boolean and number values to a string, but do not @@ -165,7 +165,7 @@ function serializeString(outputValue: mixed): string { ); } -function coerceString(inputValue: mixed): string { +function coerceString(inputValue: unknown): string { if (typeof inputValue !== 'string') { throw new GraphQLError( `String cannot represent a non string value: ${inspect(inputValue)}`, @@ -191,7 +191,7 @@ export const GraphQLString = new GraphQLScalarType({ }, }); -function serializeBoolean(outputValue: mixed): boolean { +function serializeBoolean(outputValue: unknown): boolean { const coercedValue = serializeObject(outputValue); if (typeof coercedValue === 'boolean') { @@ -205,7 +205,7 @@ function serializeBoolean(outputValue: mixed): boolean { ); } -function coerceBoolean(inputValue: mixed): boolean { +function coerceBoolean(inputValue: unknown): boolean { if (typeof inputValue !== 'boolean') { throw new GraphQLError( `Boolean cannot represent a non boolean value: ${inspect(inputValue)}`, @@ -230,7 +230,7 @@ export const GraphQLBoolean = new GraphQLScalarType({ }, }); -function serializeID(outputValue: mixed): string { +function serializeID(outputValue: unknown): string { const coercedValue = serializeObject(outputValue); if (typeof coercedValue === 'string') { @@ -242,7 +242,7 @@ function serializeID(outputValue: mixed): string { throw new GraphQLError(`ID cannot represent value: ${inspect(outputValue)}`); } -function coerceID(inputValue: mixed): string { +function coerceID(inputValue: unknown): string { if (typeof inputValue === 'string') { return inputValue; } diff --git a/src/type/schema.ts b/src/type/schema.ts index 65c8738a8d3..845d6119385 100644 --- a/src/type/schema.ts +++ b/src/type/schema.ts @@ -42,14 +42,14 @@ import { /** * Test if the given value is a GraphQL schema. */ -declare function isSchema(schema: mixed): boolean %checks(schema instanceof +declare function isSchema(schema: unknown): boolean %checks(schema instanceof GraphQLSchema); // eslint-disable-next-line no-redeclare export function isSchema(schema) { return instanceOf(schema, GraphQLSchema); } -export function assertSchema(schema: mixed): GraphQLSchema { +export function assertSchema(schema: unknown): GraphQLSchema { if (!isSchema(schema)) { throw new Error(`Expected ${inspect(schema)} to be a GraphQL schema.`); } @@ -121,7 +121,7 @@ export function assertSchema(schema: mixed): GraphQLSchema { */ export class GraphQLSchema { description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?ReadOnlyObjMap; astNode: ?SchemaDefinitionNode; extensionASTNodes: ?ReadonlyArray; @@ -370,7 +370,7 @@ export type GraphQLSchemaConfig = { subscription?: ?GraphQLObjectType, types?: ?Array, directives?: ?Array, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?SchemaDefinitionNode, extensionASTNodes?: ?ReadonlyArray, ...GraphQLSchemaValidationOptions, @@ -384,7 +384,7 @@ export type GraphQLSchemaNormalizedConfig = { description: ?string, types: Array, directives: Array, - extensions: ?ReadOnlyObjMap, + extensions: ?ReadOnlyObjMap, extensionASTNodes: ReadonlyArray, assumeValid: boolean, }; diff --git a/src/utilities/TypeInfo.ts b/src/utilities/TypeInfo.ts index 4fdbef20152..5d4ee245243 100644 --- a/src/utilities/TypeInfo.ts +++ b/src/utilities/TypeInfo.ts @@ -46,8 +46,8 @@ export class TypeInfo { _typeStack: Array; _parentTypeStack: Array; _inputTypeStack: Array; - _fieldDefStack: Array>; - _defaultValueStack: Array; + _fieldDefStack: Array>; + _defaultValueStack: Array; _directive: ?GraphQLDirective; _argument: ?GraphQLArgument; _enumValue: ?GraphQLEnumValue; @@ -110,13 +110,13 @@ export class TypeInfo { } } - getFieldDef(): ?GraphQLField { + getFieldDef(): ?GraphQLField { if (this._fieldDefStack.length > 0) { return this._fieldDefStack[this._fieldDefStack.length - 1]; } } - getDefaultValue(): ?mixed { + getDefaultValue(): ?unknown { if (this._defaultValueStack.length > 0) { return this._defaultValueStack[this._defaultValueStack.length - 1]; } @@ -136,13 +136,13 @@ export class TypeInfo { enter(node: ASTNode) { const schema = this._schema; - // Note: many of the types below are explicitly typed as "mixed" to drop + // Note: many of the types below are explicitly typed as "unknown" to drop // any assumptions of a valid schema to ensure runtime types are properly // checked before continuing since TypeInfo is used as part of validation // which occurs before guarantees of schema and document validity. switch (node.kind) { case Kind.SELECTION_SET: { - const namedType: mixed = getNamedType(this.getType()); + const namedType: unknown = getNamedType(this.getType()); this._parentTypeStack.push( isCompositeType(namedType) ? namedType : undefined, ); @@ -151,7 +151,7 @@ export class TypeInfo { case Kind.FIELD: { const parentType = this.getParentType(); let fieldDef; - let fieldType: mixed; + let fieldType: unknown; if (parentType) { fieldDef = this._getFieldDef(schema, parentType, node); if (fieldDef) { @@ -166,7 +166,7 @@ export class TypeInfo { this._directive = schema.getDirective(node.name.value); break; case Kind.OPERATION_DEFINITION: { - let type: mixed; + let type: unknown; switch (node.operation) { case 'query': type = schema.getQueryType(); @@ -184,14 +184,14 @@ export class TypeInfo { case Kind.INLINE_FRAGMENT: case Kind.FRAGMENT_DEFINITION: { const typeConditionAST = node.typeCondition; - const outputType: mixed = typeConditionAST + const outputType: unknown = typeConditionAST ? typeFromAST(schema, typeConditionAST) : getNamedType(this.getType()); this._typeStack.push(isOutputType(outputType) ? outputType : undefined); break; } case Kind.VARIABLE_DEFINITION: { - const inputType: mixed = typeFromAST(schema, node.type); + const inputType: unknown = typeFromAST(schema, node.type); this._inputTypeStack.push( isInputType(inputType) ? inputType : undefined, ); @@ -199,7 +199,7 @@ export class TypeInfo { } case Kind.ARGUMENT: { let argDef; - let argType: mixed; + let argType: unknown; const fieldOrDirective = this.getDirective() ?? this.getFieldDef(); if (fieldOrDirective) { argDef = fieldOrDirective.args.find( @@ -215,8 +215,8 @@ export class TypeInfo { break; } case Kind.LIST: { - const listType: mixed = getNullableType(this.getInputType()); - const itemType: mixed = isListType(listType) + const listType: unknown = getNullableType(this.getInputType()); + const itemType: unknown = isListType(listType) ? listType.ofType : listType; // List positions never have a default value. @@ -225,7 +225,7 @@ export class TypeInfo { break; } case Kind.OBJECT_FIELD: { - const objectType: mixed = getNamedType(this.getInputType()); + const objectType: unknown = getNamedType(this.getInputType()); let inputFieldType: GraphQLInputType | void; let inputField: GraphQLInputField | void; if (isInputObjectType(objectType)) { @@ -243,7 +243,7 @@ export class TypeInfo { break; } case Kind.ENUM: { - const enumType: mixed = getNamedType(this.getInputType()); + const enumType: unknown = getNamedType(this.getInputType()); let enumValue; if (isEnumType(enumType)) { enumValue = enumType.getValue(node.value); @@ -300,7 +300,7 @@ function getFieldDef( schema: GraphQLSchema, parentType: GraphQLType, fieldNode: FieldNode, -): ?GraphQLField { +): ?GraphQLField { const name = fieldNode.name.value; if ( name === SchemaMetaFieldDef.name && diff --git a/src/utilities/__tests__/coerceInputValue-test.ts b/src/utilities/__tests__/coerceInputValue-test.ts index 4da5636769c..f2382e85825 100644 --- a/src/utilities/__tests__/coerceInputValue-test.ts +++ b/src/utilities/__tests__/coerceInputValue-test.ts @@ -25,7 +25,7 @@ function expectErrors(result: any) { } describe('coerceInputValue', () => { - function coerceValue(inputValue: mixed, type: GraphQLInputType) { + function coerceValue(inputValue: unknown, type: GraphQLInputType) { const errors = []; const value = coerceInputValue( inputValue, diff --git a/src/utilities/__tests__/printSchema-test.ts b/src/utilities/__tests__/printSchema-test.ts index 2bedc1478fb..b3c0bfbfa91 100644 --- a/src/utilities/__tests__/printSchema-test.ts +++ b/src/utilities/__tests__/printSchema-test.ts @@ -30,7 +30,7 @@ function expectPrintedSchema(schema: GraphQLSchema) { return expect(schemaText); } -function buildSingleFieldSchema(fieldConfig: GraphQLFieldConfig) { +function buildSingleFieldSchema(fieldConfig: GraphQLFieldConfig) { const Query = new GraphQLObjectType({ name: 'Query', fields: { singleField: fieldConfig }, diff --git a/src/utilities/__tests__/typeComparators-test.ts b/src/utilities/__tests__/typeComparators-test.ts index 3f2a87ae780..adf830b4612 100644 --- a/src/utilities/__tests__/typeComparators-test.ts +++ b/src/utilities/__tests__/typeComparators-test.ts @@ -53,7 +53,7 @@ describe('typeComparators', () => { }); describe('isTypeSubTypeOf', () => { - function testSchema(fields: GraphQLFieldConfigMap) { + function testSchema(fields: GraphQLFieldConfigMap) { return new GraphQLSchema({ query: new GraphQLObjectType({ name: 'Query', diff --git a/src/utilities/__tests__/valueFromAST-test.ts b/src/utilities/__tests__/valueFromAST-test.ts index f4dc325206b..ffb0baa5447 100644 --- a/src/utilities/__tests__/valueFromAST-test.ts +++ b/src/utilities/__tests__/valueFromAST-test.ts @@ -29,7 +29,7 @@ describe('valueFromAST', () => { function expectValueFrom( valueText: string, type: GraphQLInputType, - variables: ?ObjMap, + variables: ?ObjMap, ) { const ast = parseValue(valueText); const value = valueFromAST(ast, type, variables); diff --git a/src/utilities/__tests__/valueFromASTUntyped-test.ts b/src/utilities/__tests__/valueFromASTUntyped-test.ts index 5e971a43f61..fb1babcdc11 100644 --- a/src/utilities/__tests__/valueFromASTUntyped-test.ts +++ b/src/utilities/__tests__/valueFromASTUntyped-test.ts @@ -8,7 +8,7 @@ import { parseValue } from '../../language/parser'; import { valueFromASTUntyped } from '../valueFromASTUntyped'; describe('valueFromASTUntyped', () => { - function expectValueFrom(valueText: string, variables?: ?ObjMap) { + function expectValueFrom(valueText: string, variables?: ?ObjMap) { const ast = parseValue(valueText); const value = valueFromASTUntyped(ast, variables); return expect(value); diff --git a/src/utilities/astFromValue.d.ts b/src/utilities/astFromValue.d.ts index 19f0a8feed4..50647b9f37a 100644 --- a/src/utilities/astFromValue.d.ts +++ b/src/utilities/astFromValue.d.ts @@ -16,7 +16,7 @@ import { GraphQLInputType } from '../type/definition'; * | Boolean | Boolean | * | String | String / Enum Value | * | Number | Int / Float | - * | Mixed | Enum Value | + * | unknown | Enum Value | * | null | NullValue | * */ diff --git a/src/utilities/astFromValue.ts b/src/utilities/astFromValue.ts index da5ad950518..33849a8bb4c 100644 --- a/src/utilities/astFromValue.ts +++ b/src/utilities/astFromValue.ts @@ -35,11 +35,11 @@ import { * | Boolean | Boolean | * | String | String / Enum Value | * | Number | Int / Float | - * | Mixed | Enum Value | + * | unknown | Enum Value | * | null | NullValue | * */ -export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode { +export function astFromValue(value: unknown, type: GraphQLInputType): ?ValueNode { if (isNonNullType(type)) { const astValue = astFromValue(value, type.ofType); if (astValue?.kind === Kind.NULL) { diff --git a/src/utilities/buildClientSchema.ts b/src/utilities/buildClientSchema.ts index b5edf7aad1d..4e9117149d8 100644 --- a/src/utilities/buildClientSchema.ts +++ b/src/utilities/buildClientSchema.ts @@ -310,7 +310,7 @@ export function buildClientSchema( function buildFieldDefMap( typeIntrospection: IntrospectionObjectType | IntrospectionInterfaceType, - ): GraphQLFieldConfigMap { + ): GraphQLFieldConfigMap { if (!typeIntrospection.fields) { throw new Error( `Introspection result missing fields: ${inspect(typeIntrospection)}.`, @@ -326,7 +326,7 @@ export function buildClientSchema( function buildField( fieldIntrospection: IntrospectionField, - ): GraphQLFieldConfig { + ): GraphQLFieldConfig { const type = getType(fieldIntrospection.type); if (!isOutputType(type)) { const typeStr = inspect(type); diff --git a/src/utilities/coerceInputValue.ts b/src/utilities/coerceInputValue.ts index 1c24c467b57..ae1327efd08 100644 --- a/src/utilities/coerceInputValue.ts +++ b/src/utilities/coerceInputValue.ts @@ -22,7 +22,7 @@ import { type OnErrorCB = ( path: ReadonlyArray, - invalidValue: mixed, + invalidValue: unknown, error: GraphQLError, ) => void; @@ -30,16 +30,16 @@ type OnErrorCB = ( * Coerces a JavaScript value given a GraphQL Input Type. */ export function coerceInputValue( - inputValue: mixed, + inputValue: unknown, type: GraphQLInputType, onError?: OnErrorCB = defaultOnError, -): mixed { +): unknown { return coerceInputValueImpl(inputValue, type, onError); } function defaultOnError( path: ReadonlyArray, - invalidValue: mixed, + invalidValue: unknown, error: GraphQLError, ): void { let errorPrefix = 'Invalid value ' + inspect(invalidValue); @@ -51,11 +51,11 @@ function defaultOnError( } function coerceInputValueImpl( - inputValue: mixed, + inputValue: unknown, type: GraphQLInputType, onError: OnErrorCB, path: Path | void, -): mixed { +): unknown { if (isNonNullType(type)) { if (inputValue != null) { return coerceInputValueImpl(inputValue, type.ofType, onError, path); diff --git a/src/utilities/extendSchema.ts b/src/utilities/extendSchema.ts index e0520557b97..b9619b7ae9a 100644 --- a/src/utilities/extendSchema.ts +++ b/src/utilities/extendSchema.ts @@ -377,8 +377,8 @@ export function extendSchemaImpl( } function extendField( - field: GraphQLFieldConfig, - ): GraphQLFieldConfig { + field: GraphQLFieldConfig, + ): GraphQLFieldConfig { return { ...field, type: replaceType(field.type), @@ -460,7 +460,7 @@ export function extendSchemaImpl( | ObjectTypeDefinitionNode | ObjectTypeExtensionNode, >, - ): GraphQLFieldConfigMap { + ): GraphQLFieldConfigMap { const fieldConfigMap = Object.create(null); for (const node of nodes) { // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') diff --git a/src/utilities/findBreakingChanges.ts b/src/utilities/findBreakingChanges.ts index f210d4a707b..e8d3a7617b0 100644 --- a/src/utilities/findBreakingChanges.ts +++ b/src/utilities/findBreakingChanges.ts @@ -379,8 +379,8 @@ function findFieldChanges( function findArgChanges( oldType: GraphQLObjectType | GraphQLInterfaceType, - oldField: GraphQLField, - newField: GraphQLField, + oldField: GraphQLField, + newField: GraphQLField, ): Array { const schemaChanges = []; const argsDiff = diff(oldField.args, newField.args); @@ -535,7 +535,7 @@ function typeKindName(type: GraphQLNamedType): string { invariant(false, 'Unexpected type: ' + inspect((type: empty))); } -function stringifyValue(value: mixed, type: GraphQLInputType): string { +function stringifyValue(value: unknown, type: GraphQLInputType): string { const ast = astFromValue(value, type); invariant(ast != null); diff --git a/src/utilities/valueFromAST.d.ts b/src/utilities/valueFromAST.d.ts index acde6ba9dfb..4d2426a7007 100644 --- a/src/utilities/valueFromAST.d.ts +++ b/src/utilities/valueFromAST.d.ts @@ -19,7 +19,7 @@ import { GraphQLInputType } from '../type/definition'; * | Boolean | Boolean | * | String | String | * | Int / Float | Number | - * | Enum Value | Mixed | + * | Enum Value | unknown | * | NullValue | null | * */ diff --git a/src/utilities/valueFromAST.ts b/src/utilities/valueFromAST.ts index 7afed422820..ce2dc042bb0 100644 --- a/src/utilities/valueFromAST.ts +++ b/src/utilities/valueFromAST.ts @@ -32,15 +32,15 @@ import { * | Boolean | Boolean | * | String | String | * | Int / Float | Number | - * | Enum Value | Mixed | + * | Enum Value | unknown | * | NullValue | null | * */ export function valueFromAST( valueNode: ?ValueNode, type: GraphQLInputType, - variables?: ?ObjMap, -): mixed | void { + variables?: ?ObjMap, +): unknown | void { if (!valueNode) { // When there is no node, then there is also no value. // Importantly, this is different from returning the value null. @@ -154,7 +154,7 @@ export function valueFromAST( // in the set of variables. function isMissingVariable( valueNode: ValueNode, - variables: ?ObjMap, + variables: ?ObjMap, ): boolean { return ( valueNode.kind === Kind.VARIABLE && diff --git a/src/utilities/valueFromASTUntyped.ts b/src/utilities/valueFromASTUntyped.ts index 3b70329bda1..0c704b03d5b 100644 --- a/src/utilities/valueFromASTUntyped.ts +++ b/src/utilities/valueFromASTUntyped.ts @@ -24,8 +24,8 @@ import type { ValueNode } from '../language/ast'; */ export function valueFromASTUntyped( valueNode: ValueNode, - variables?: ?ObjMap, -): mixed { + variables?: ?ObjMap, +): unknown { switch (valueNode.kind) { case Kind.NULL: return null; diff --git a/src/validation/ValidationContext.ts b/src/validation/ValidationContext.ts index 5d10009f3fd..eed3d7dd395 100644 --- a/src/validation/ValidationContext.ts +++ b/src/validation/ValidationContext.ts @@ -32,7 +32,7 @@ type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode; type VariableUsage = { readonly node: VariableNode, readonly type: ?GraphQLInputType, - readonly defaultValue: ?mixed, + readonly defaultValue: ?unknown, }; /** @@ -233,7 +233,7 @@ export class ValidationContext extends ASTValidationContext { return this._typeInfo.getParentInputType(); } - getFieldDef(): ?GraphQLField { + getFieldDef(): ?GraphQLField { return this._typeInfo.getFieldDef(); } diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts index a954a3928dd..0d101f90fad 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.ts @@ -99,7 +99,7 @@ type ConflictReasonMessage = string | Array; type NodeAndDef = [ GraphQLCompositeType, FieldNode, - ?GraphQLField, + ?GraphQLField, ]; // Map of array of those. type NodeAndDefCollection = ObjMap>; diff --git a/src/validation/rules/VariablesInAllowedPositionRule.ts b/src/validation/rules/VariablesInAllowedPositionRule.ts index 8d0cbbf26c7..96be8306bdf 100644 --- a/src/validation/rules/VariablesInAllowedPositionRule.ts +++ b/src/validation/rules/VariablesInAllowedPositionRule.ts @@ -81,7 +81,7 @@ function allowedVariableUsage( varType: GraphQLType, varDefaultValue: ?ValueNode, locationType: GraphQLType, - locationDefaultValue: ?mixed, + locationDefaultValue: ?unknown, ): boolean { if (isNonNullType(locationType) && !isNonNullType(varType)) { const hasNonNullVariableDefaultValue =