Skip to content

Commit

Permalink
convert mixed (flow) to unknown (TS)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Oct 27, 2020
1 parent 75de44a commit cd55ba9
Show file tree
Hide file tree
Showing 58 changed files with 307 additions and 307 deletions.
6 changes: 3 additions & 3 deletions src/error/GraphQLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ 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,
nodes?: ReadonlyArray<ASTNode> | ASTNode | void | null,
source?: ?Source,
positions?: ?ReadonlyArray<number>,
path?: ?ReadonlyArray<string | number>,
originalError?: ?(Error & { readonly extensions?: mixed, ... }),
extensions?: ?{ [key: string]: mixed, ... },
originalError?: ?(Error & { readonly extensions?: unknown, ... }),
extensions?: ?{ [key: string]: unknown, ... },
): void {
super(message);

Expand Down
2 changes: 1 addition & 1 deletion src/error/formatError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, ... },
};
2 changes: 1 addition & 1 deletion src/error/locatedError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GraphQLError } from './GraphQLError';
* document responsible for the original Error.
*/
export function locatedError(
rawOriginalError: mixed,
rawOriginalError: unknown,
nodes: ASTNode | ReadonlyArray<ASTNode> | void | null,
path?: ?ReadonlyArray<string | number>,
): GraphQLError {
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/abstract-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/execution/__tests__/lists-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }'),
Expand Down Expand Up @@ -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 }');
Expand All @@ -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<mixed> {
function promisify(value: unknown): Promise<unknown> {
return value instanceof Error
? Promise.reject(value)
: Promise.resolve(value);
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/nonnull-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const schema = buildSchema(`

function executeQuery(
query: string,
rootValue: mixed,
rootValue: unknown,
): ExecutionResult | Promise<ExecutionResult> {
return execute({ schema, document: parse(query), rootValue });
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/resolve-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
84 changes: 42 additions & 42 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ import {
export type ExecutionContext = {
schema: GraphQLSchema,
fragments: ObjMap<FragmentDefinitionNode>,
rootValue: mixed,
contextValue: mixed,
rootValue: unknown,
contextValue: unknown,
operation: OperationDefinitionNode,
variableValues: { [variable: string]: mixed, ... },
variableValues: { [variable: string]: unknown, ... },
fieldResolver: GraphQLFieldResolver<any, any>,
typeResolver: GraphQLTypeResolver<any, any>,
errors: Array<GraphQLError>,
Expand All @@ -113,22 +113,22 @@ export type ExecutionContext = {
*/
export type ExecutionResult = {
errors?: ReadonlyArray<GraphQLError>,
data?: ObjMap<mixed> | null,
extensions?: ObjMap<mixed>,
data?: ObjMap<unknown> | null,
extensions?: ObjMap<unknown>,
};

export type FormattedExecutionResult = {
errors?: ReadonlyArray<GraphQLFormattedError>,
data?: ObjMap<mixed> | null,
extensions?: ObjMap<mixed>,
data?: ObjMap<unknown> | null,
extensions?: ObjMap<unknown>,
};

export type ExecutionArgs = {
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: mixed,
contextValue?: mixed,
variableValues?: ?{ readonly [variable: string]: mixed, ... },
variableValues?: ?{ readonly [variable: string]: unknown, ... },
operationName?: ?string,
fieldResolver?: ?GraphQLFieldResolver<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
Expand Down Expand Up @@ -210,7 +210,7 @@ export function executeSync(args: ExecutionArgs): ExecutionResult {
*/
function buildResponse(
exeContext: ExecutionContext,
data: PromiseOrValue<ObjMap<mixed> | null>,
data: PromiseOrValue<ObjMap<unknown> | null>,
): PromiseOrValue<ExecutionResult> {
if (isPromise(data)) {
return data.then((resolved) => buildResponse(exeContext, resolved));
Expand All @@ -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.');

Expand All @@ -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<mixed, mixed>,
typeResolver?: ?GraphQLTypeResolver<mixed, mixed>,
fieldResolver: ?GraphQLFieldResolver<unknown, unknown>,
typeResolver?: ?GraphQLTypeResolver<unknown, unknown>,
): ReadonlyArray<GraphQLError> | ExecutionContext {
let operation: OperationDefinitionNode | void;
const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null);
Expand Down Expand Up @@ -325,8 +325,8 @@ export function buildExecutionContext(
function executeOperation(
exeContext: ExecutionContext,
operation: OperationDefinitionNode,
rootValue: mixed,
): PromiseOrValue<ObjMap<mixed> | null> {
rootValue: unknown,
): PromiseOrValue<ObjMap<unknown> | null> {
const type = getOperationRootType(exeContext.schema, operation);
const fields = collectFields(
exeContext,
Expand Down Expand Up @@ -366,10 +366,10 @@ function executeOperation(
function executeFieldsSerially(
exeContext: ExecutionContext,
parentType: GraphQLObjectType,
sourceValue: mixed,
sourceValue: unknown,
path: Path | void,
fields: ObjMap<Array<FieldNode>>,
): PromiseOrValue<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<unknown>> {
return promiseReduce(
Object.keys(fields),
(results, responseName) => {
Expand Down Expand Up @@ -405,10 +405,10 @@ function executeFieldsSerially(
function executeFields(
exeContext: ExecutionContext,
parentType: GraphQLObjectType,
sourceValue: mixed,
sourceValue: unknown,
path: Path | void,
fields: ObjMap<Array<FieldNode>>,
): PromiseOrValue<ObjMap<mixed>> {
): PromiseOrValue<ObjMap<unknown>> {
const results = Object.create(null);
let containsPromise = false;

Expand Down Expand Up @@ -584,10 +584,10 @@ function getFieldEntryKey(node: FieldNode): string {
function resolveField(
exeContext: ExecutionContext,
parentType: GraphQLObjectType,
source: mixed,
source: unknown,
fieldNodes: ReadonlyArray<FieldNode>,
path: Path,
): PromiseOrValue<mixed> {
): PromiseOrValue<unknown> {
const fieldNode = fieldNodes[0];
const fieldName = fieldNode.name.value;

Expand Down Expand Up @@ -661,7 +661,7 @@ function resolveField(
*/
export function buildResolveInfo(
exeContext: ExecutionContext,
fieldDef: GraphQLField<mixed, mixed>,
fieldDef: GraphQLField<unknown, unknown>,
fieldNodes: ReadonlyArray<FieldNode>,
parentType: GraphQLObjectType,
path: Path,
Expand Down Expand Up @@ -726,8 +726,8 @@ function completeValue(
fieldNodes: ReadonlyArray<FieldNode>,
info: GraphQLResolveInfo,
path: Path,
result: mixed,
): PromiseOrValue<mixed> {
result: unknown,
): PromiseOrValue<unknown> {
// If result is an Error, throw a located error.
if (result instanceof Error) {
throw result;
Expand Down Expand Up @@ -819,8 +819,8 @@ function completeListValue(
fieldNodes: ReadonlyArray<FieldNode>,
info: GraphQLResolveInfo,
path: Path,
result: mixed,
): PromiseOrValue<ReadonlyArray<mixed>> {
result: unknown,
): PromiseOrValue<ReadonlyArray<unknown>> {
if (!isCollection(result)) {
throw new GraphQLError(
`Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`,
Expand Down Expand Up @@ -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(
Expand All @@ -907,8 +907,8 @@ function completeAbstractValue(
fieldNodes: ReadonlyArray<FieldNode>,
info: GraphQLResolveInfo,
path: Path,
result: mixed,
): PromiseOrValue<ObjMap<mixed>> {
result: unknown,
): PromiseOrValue<ObjMap<unknown>> {
const resolveTypeFn = returnType.resolveType ?? exeContext.typeResolver;
const contextValue = exeContext.contextValue;
const runtimeType = resolveTypeFn(result, contextValue, info, returnType);
Expand Down Expand Up @@ -951,12 +951,12 @@ function completeAbstractValue(
}

function ensureValidRuntimeType(
runtimeTypeName: mixed,
runtimeTypeName: unknown,
exeContext: ExecutionContext,
returnType: GraphQLAbstractType,
fieldNodes: ReadonlyArray<FieldNode>,
info: GraphQLResolveInfo,
result: mixed,
result: unknown,
): GraphQLObjectType {
if (runtimeTypeName == null) {
throw new GraphQLError(
Expand Down Expand Up @@ -1014,8 +1014,8 @@ function completeObjectValue(
fieldNodes: ReadonlyArray<FieldNode>,
info: GraphQLResolveInfo,
path: Path,
result: mixed,
): PromiseOrValue<ObjMap<mixed>> {
result: unknown,
): PromiseOrValue<ObjMap<unknown>> {
// 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.
Expand Down Expand Up @@ -1053,7 +1053,7 @@ function completeObjectValue(

function invalidReturnTypeError(
returnType: GraphQLObjectType,
result: mixed,
result: unknown,
fieldNodes: ReadonlyArray<FieldNode>,
): GraphQLError {
return new GraphQLError(
Expand All @@ -1067,8 +1067,8 @@ function collectAndExecuteSubfields(
returnType: GraphQLObjectType,
fieldNodes: ReadonlyArray<FieldNode>,
path: Path,
result: mixed,
): PromiseOrValue<ObjMap<mixed>> {
result: unknown,
): PromiseOrValue<ObjMap<unknown>> {
// Collect sub-fields to execute to complete this value.
const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
return executeFields(exeContext, returnType, result, path, subFieldNodes);
Expand Down Expand Up @@ -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<mixed, mixed> = function (
export const defaultTypeResolver: GraphQLTypeResolver<unknown, unknown> = function (
value,
contextValue,
info,
Expand Down Expand Up @@ -1158,8 +1158,8 @@ export const defaultTypeResolver: GraphQLTypeResolver<mixed, mixed> = 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') {
Expand All @@ -1186,7 +1186,7 @@ export function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLObjectType,
fieldName: string,
): ?GraphQLField<mixed, mixed> {
): ?GraphQLField<unknown, unknown> {
if (
fieldName === SchemaMetaFieldDef.name &&
schema.getQueryType() === parentType
Expand Down
Loading

0 comments on commit cd55ba9

Please sign in to comment.