Skip to content

Commit cd55ba9

Browse files
committed
convert mixed (flow) to unknown (TS)
1 parent 75de44a commit cd55ba9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+307
-307
lines changed

src/error/GraphQLError.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ export class GraphQLError extends Error {
7272
/**
7373
* Extension fields to add to the formatted error.
7474
*/
75-
readonly extensions: { [key: string]: mixed, ... } | void;
75+
readonly extensions: { [key: string]: unknown, ... } | void;
7676

7777
constructor(
7878
message: string,
7979
nodes?: ReadonlyArray<ASTNode> | ASTNode | void | null,
8080
source?: ?Source,
8181
positions?: ?ReadonlyArray<number>,
8282
path?: ?ReadonlyArray<string | number>,
83-
originalError?: ?(Error & { readonly extensions?: mixed, ... }),
84-
extensions?: ?{ [key: string]: mixed, ... },
83+
originalError?: ?(Error & { readonly extensions?: unknown, ... }),
84+
extensions?: ?{ [key: string]: unknown, ... },
8585
): void {
8686
super(message);
8787

src/error/formatError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ export type GraphQLFormattedError = {
4646
* Reserved for implementors to extend the protocol however they see fit,
4747
* and hence there are no additional restrictions on its contents.
4848
*/
49-
readonly extensions?: { [key: string]: mixed, ... },
49+
readonly extensions?: { [key: string]: unknown, ... },
5050
};

src/error/locatedError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { GraphQLError } from './GraphQLError';
1010
* document responsible for the original Error.
1111
*/
1212
export function locatedError(
13-
rawOriginalError: mixed,
13+
rawOriginalError: unknown,
1414
nodes: ASTNode | ReadonlyArray<ASTNode> | void | null,
1515
path?: ?ReadonlyArray<string | number>,
1616
): GraphQLError {

src/execution/__tests__/abstract-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { executeSync, execute } from '../execute';
1919
async function executeQuery(args: {
2020
schema: GraphQLSchema,
2121
query: string,
22-
rootValue?: mixed,
22+
rootValue?: unknown,
2323
}) {
2424
const { schema, query, rootValue } = args;
2525
const document = parse(query);
@@ -533,7 +533,7 @@ describe('Execute: Handles execution of abstract types', () => {
533533
}
534534
`);
535535

536-
function expectError({ forTypeName }: { forTypeName: mixed }) {
536+
function expectError({ forTypeName }: { forTypeName: unknown }) {
537537
const rootValue = { pet: { __typename: forTypeName } };
538538
const result = executeSync({ schema, document, rootValue });
539539
return {

src/execution/__tests__/lists-test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { buildSchema } from '../../utilities/buildASTSchema';
88
import { execute, executeSync } from '../execute';
99

1010
describe('Execute: Accepts any iterable as list value', () => {
11-
function complete(rootValue: mixed) {
11+
function complete(rootValue: unknown) {
1212
return executeSync({
1313
schema: buildSchema('type Query { listField: [String] }'),
1414
document: parse('{ listField }'),
@@ -65,7 +65,7 @@ describe('Execute: Accepts any iterable as list value', () => {
6565
});
6666

6767
describe('Execute: Handles list nullability', () => {
68-
async function complete(args: { listField: mixed, as: string }) {
68+
async function complete(args: { listField: unknown, as: string }) {
6969
const { listField, as } = args;
7070
const schema = buildSchema(`type Query { listField: ${as} }`);
7171
const document = parse('{ listField }');
@@ -85,11 +85,11 @@ describe('Execute: Handles list nullability', () => {
8585
}
8686
return result;
8787

88-
function executeQuery(listValue: mixed) {
88+
function executeQuery(listValue: unknown) {
8989
return execute({ schema, document, rootValue: { listField: listValue } });
9090
}
9191

92-
function promisify(value: mixed): Promise<mixed> {
92+
function promisify(value: unknown): Promise<unknown> {
9393
return value instanceof Error
9494
? Promise.reject(value)
9595
: Promise.resolve(value);

src/execution/__tests__/nonnull-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const schema = buildSchema(`
106106

107107
function executeQuery(
108108
query: string,
109-
rootValue: mixed,
109+
rootValue: unknown,
110110
): ExecutionResult | Promise<ExecutionResult> {
111111
return execute({ schema, document: parse(query), rootValue });
112112
}
@@ -122,7 +122,7 @@ function patchData(data: ExecutionResult): ExecutionResult {
122122
return JSON.parse(patch(JSON.stringify(data)));
123123
}
124124

125-
async function executeSyncAndAsync(query: string, rootValue: mixed) {
125+
async function executeSyncAndAsync(query: string, rootValue: unknown) {
126126
const syncResult = executeSync({ schema, document: parse(query), rootValue });
127127
const asyncResult = await execute({
128128
schema,

src/execution/__tests__/resolve-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Execute: resolve function', () => {
9595
resolve: (source, args) => JSON.stringify([source, args]),
9696
});
9797

98-
function executeQuery(query: string, rootValue?: mixed) {
98+
function executeQuery(query: string, rootValue?: unknown) {
9999
const document = parse(query);
100100
return executeSync({ schema, document, rootValue });
101101
}

src/execution/__tests__/variables-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const schema = new GraphQLSchema({ query: TestType });
119119

120120
function executeQuery(
121121
query: string,
122-
variableValues?: { [variable: string]: mixed, ... },
122+
variableValues?: { [variable: string]: unknown, ... },
123123
) {
124124
const document = parse(query);
125125
return executeSync({ schema, document, variableValues });

src/execution/execute.ts

+42-42
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ import {
9595
export type ExecutionContext = {
9696
schema: GraphQLSchema,
9797
fragments: ObjMap<FragmentDefinitionNode>,
98-
rootValue: mixed,
99-
contextValue: mixed,
98+
rootValue: unknown,
99+
contextValue: unknown,
100100
operation: OperationDefinitionNode,
101-
variableValues: { [variable: string]: mixed, ... },
101+
variableValues: { [variable: string]: unknown, ... },
102102
fieldResolver: GraphQLFieldResolver<any, any>,
103103
typeResolver: GraphQLTypeResolver<any, any>,
104104
errors: Array<GraphQLError>,
@@ -113,22 +113,22 @@ export type ExecutionContext = {
113113
*/
114114
export type ExecutionResult = {
115115
errors?: ReadonlyArray<GraphQLError>,
116-
data?: ObjMap<mixed> | null,
117-
extensions?: ObjMap<mixed>,
116+
data?: ObjMap<unknown> | null,
117+
extensions?: ObjMap<unknown>,
118118
};
119119

120120
export type FormattedExecutionResult = {
121121
errors?: ReadonlyArray<GraphQLFormattedError>,
122-
data?: ObjMap<mixed> | null,
123-
extensions?: ObjMap<mixed>,
122+
data?: ObjMap<unknown> | null,
123+
extensions?: ObjMap<unknown>,
124124
};
125125

126126
export type ExecutionArgs = {
127127
schema: GraphQLSchema,
128128
document: DocumentNode,
129129
rootValue?: mixed,
130130
contextValue?: mixed,
131-
variableValues?: ?{ readonly [variable: string]: mixed, ... },
131+
variableValues?: ?{ readonly [variable: string]: unknown, ... },
132132
operationName?: ?string,
133133
fieldResolver?: ?GraphQLFieldResolver<any, any>,
134134
typeResolver?: ?GraphQLTypeResolver<any, any>,
@@ -210,7 +210,7 @@ export function executeSync(args: ExecutionArgs): ExecutionResult {
210210
*/
211211
function buildResponse(
212212
exeContext: ExecutionContext,
213-
data: PromiseOrValue<ObjMap<mixed> | null>,
213+
data: PromiseOrValue<ObjMap<unknown> | null>,
214214
): PromiseOrValue<ExecutionResult> {
215215
if (isPromise(data)) {
216216
return data.then((resolved) => buildResponse(exeContext, resolved));
@@ -229,7 +229,7 @@ function buildResponse(
229229
export function assertValidExecutionArguments(
230230
schema: GraphQLSchema,
231231
document: DocumentNode,
232-
rawVariableValues: ?{ readonly [variable: string]: mixed, ... },
232+
rawVariableValues: ?{ readonly [variable: string]: unknown, ... },
233233
): void {
234234
devAssert(document, 'Must provide document.');
235235

@@ -254,12 +254,12 @@ export function assertValidExecutionArguments(
254254
export function buildExecutionContext(
255255
schema: GraphQLSchema,
256256
document: DocumentNode,
257-
rootValue: mixed,
258-
contextValue: mixed,
259-
rawVariableValues: ?{ readonly [variable: string]: mixed, ... },
257+
rootValue: unknown,
258+
contextValue: unknown,
259+
rawVariableValues: ?{ readonly [variable: string]: unknown, ... },
260260
operationName: ?string,
261-
fieldResolver: ?GraphQLFieldResolver<mixed, mixed>,
262-
typeResolver?: ?GraphQLTypeResolver<mixed, mixed>,
261+
fieldResolver: ?GraphQLFieldResolver<unknown, unknown>,
262+
typeResolver?: ?GraphQLTypeResolver<unknown, unknown>,
263263
): ReadonlyArray<GraphQLError> | ExecutionContext {
264264
let operation: OperationDefinitionNode | void;
265265
const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null);
@@ -325,8 +325,8 @@ export function buildExecutionContext(
325325
function executeOperation(
326326
exeContext: ExecutionContext,
327327
operation: OperationDefinitionNode,
328-
rootValue: mixed,
329-
): PromiseOrValue<ObjMap<mixed> | null> {
328+
rootValue: unknown,
329+
): PromiseOrValue<ObjMap<unknown> | null> {
330330
const type = getOperationRootType(exeContext.schema, operation);
331331
const fields = collectFields(
332332
exeContext,
@@ -366,10 +366,10 @@ function executeOperation(
366366
function executeFieldsSerially(
367367
exeContext: ExecutionContext,
368368
parentType: GraphQLObjectType,
369-
sourceValue: mixed,
369+
sourceValue: unknown,
370370
path: Path | void,
371371
fields: ObjMap<Array<FieldNode>>,
372-
): PromiseOrValue<ObjMap<mixed>> {
372+
): PromiseOrValue<ObjMap<unknown>> {
373373
return promiseReduce(
374374
Object.keys(fields),
375375
(results, responseName) => {
@@ -405,10 +405,10 @@ function executeFieldsSerially(
405405
function executeFields(
406406
exeContext: ExecutionContext,
407407
parentType: GraphQLObjectType,
408-
sourceValue: mixed,
408+
sourceValue: unknown,
409409
path: Path | void,
410410
fields: ObjMap<Array<FieldNode>>,
411-
): PromiseOrValue<ObjMap<mixed>> {
411+
): PromiseOrValue<ObjMap<unknown>> {
412412
const results = Object.create(null);
413413
let containsPromise = false;
414414

@@ -584,10 +584,10 @@ function getFieldEntryKey(node: FieldNode): string {
584584
function resolveField(
585585
exeContext: ExecutionContext,
586586
parentType: GraphQLObjectType,
587-
source: mixed,
587+
source: unknown,
588588
fieldNodes: ReadonlyArray<FieldNode>,
589589
path: Path,
590-
): PromiseOrValue<mixed> {
590+
): PromiseOrValue<unknown> {
591591
const fieldNode = fieldNodes[0];
592592
const fieldName = fieldNode.name.value;
593593

@@ -661,7 +661,7 @@ function resolveField(
661661
*/
662662
export function buildResolveInfo(
663663
exeContext: ExecutionContext,
664-
fieldDef: GraphQLField<mixed, mixed>,
664+
fieldDef: GraphQLField<unknown, unknown>,
665665
fieldNodes: ReadonlyArray<FieldNode>,
666666
parentType: GraphQLObjectType,
667667
path: Path,
@@ -726,8 +726,8 @@ function completeValue(
726726
fieldNodes: ReadonlyArray<FieldNode>,
727727
info: GraphQLResolveInfo,
728728
path: Path,
729-
result: mixed,
730-
): PromiseOrValue<mixed> {
729+
result: unknown,
730+
): PromiseOrValue<unknown> {
731731
// If result is an Error, throw a located error.
732732
if (result instanceof Error) {
733733
throw result;
@@ -819,8 +819,8 @@ function completeListValue(
819819
fieldNodes: ReadonlyArray<FieldNode>,
820820
info: GraphQLResolveInfo,
821821
path: Path,
822-
result: mixed,
823-
): PromiseOrValue<ReadonlyArray<mixed>> {
822+
result: unknown,
823+
): PromiseOrValue<ReadonlyArray<unknown>> {
824824
if (!isCollection(result)) {
825825
throw new GraphQLError(
826826
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
@@ -886,7 +886,7 @@ function completeListValue(
886886
* Complete a Scalar or Enum by serializing to a valid value, returning
887887
* null if serialization is not possible.
888888
*/
889-
function completeLeafValue(returnType: GraphQLLeafType, result: mixed): mixed {
889+
function completeLeafValue(returnType: GraphQLLeafType, result: unknown): unknown {
890890
const serializedResult = returnType.serialize(result);
891891
if (serializedResult === undefined) {
892892
throw new Error(
@@ -907,8 +907,8 @@ function completeAbstractValue(
907907
fieldNodes: ReadonlyArray<FieldNode>,
908908
info: GraphQLResolveInfo,
909909
path: Path,
910-
result: mixed,
911-
): PromiseOrValue<ObjMap<mixed>> {
910+
result: unknown,
911+
): PromiseOrValue<ObjMap<unknown>> {
912912
const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver;
913913
const contextValue = exeContext.contextValue;
914914
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
@@ -951,12 +951,12 @@ function completeAbstractValue(
951951
}
952952

953953
function ensureValidRuntimeType(
954-
runtimeTypeName: mixed,
954+
runtimeTypeName: unknown,
955955
exeContext: ExecutionContext,
956956
returnType: GraphQLAbstractType,
957957
fieldNodes: ReadonlyArray<FieldNode>,
958958
info: GraphQLResolveInfo,
959-
result: mixed,
959+
result: unknown,
960960
): GraphQLObjectType {
961961
if (runtimeTypeName == null) {
962962
throw new GraphQLError(
@@ -1014,8 +1014,8 @@ function completeObjectValue(
10141014
fieldNodes: ReadonlyArray<FieldNode>,
10151015
info: GraphQLResolveInfo,
10161016
path: Path,
1017-
result: mixed,
1018-
): PromiseOrValue<ObjMap<mixed>> {
1017+
result: unknown,
1018+
): PromiseOrValue<ObjMap<unknown>> {
10191019
// If there is an isTypeOf predicate function, call it with the
10201020
// current result. If isTypeOf returns false, then raise an error rather
10211021
// than continuing execution.
@@ -1053,7 +1053,7 @@ function completeObjectValue(
10531053

10541054
function invalidReturnTypeError(
10551055
returnType: GraphQLObjectType,
1056-
result: mixed,
1056+
result: unknown,
10571057
fieldNodes: ReadonlyArray<FieldNode>,
10581058
): GraphQLError {
10591059
return new GraphQLError(
@@ -1067,8 +1067,8 @@ function collectAndExecuteSubfields(
10671067
returnType: GraphQLObjectType,
10681068
fieldNodes: ReadonlyArray<FieldNode>,
10691069
path: Path,
1070-
result: mixed,
1071-
): PromiseOrValue<ObjMap<mixed>> {
1070+
result: unknown,
1071+
): PromiseOrValue<ObjMap<unknown>> {
10721072
// Collect sub-fields to execute to complete this value.
10731073
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
10741074
return executeFields(exeContext, returnType, result, path, subFieldNodes);
@@ -1111,7 +1111,7 @@ function _collectSubfields(
11111111
* Otherwise, test each possible type for the abstract type by calling
11121112
* isTypeOf for the object being coerced, returning the first type that matches.
11131113
*/
1114-
export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
1114+
export const defaultTypeResolver: GraphQLTypeResolver<unknown, unknown> = function (
11151115
value,
11161116
contextValue,
11171117
info,
@@ -1158,8 +1158,8 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = function (
11581158
* of calling that function while passing along args and context value.
11591159
*/
11601160
export const defaultFieldResolver: GraphQLFieldResolver<
1161-
mixed,
1162-
mixed,
1161+
unknown,
1162+
unknown,
11631163
> = function (source: any, args, contextValue, info) {
11641164
// ensure source is a value for which property access is acceptable.
11651165
if (isObjectLike(source) || typeof source === 'function') {
@@ -1186,7 +1186,7 @@ export function getFieldDef(
11861186
schema: GraphQLSchema,
11871187
parentType: GraphQLObjectType,
11881188
fieldName: string,
1189-
): ?GraphQLField<mixed, mixed> {
1189+
): ?GraphQLField<unknown, unknown> {
11901190
if (
11911191
fieldName === SchemaMetaFieldDef.name &&
11921192
schema.getQueryType() === parentType

0 commit comments

Comments
 (0)