Skip to content

Commit 41b6975

Browse files
committed
convert ? (flow) to Maybe (TS)
1 parent cd55ba9 commit 41b6975

29 files changed

+285
-258
lines changed

src/error/GraphQLError.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Source } from '../language/source';
88
import type { SourceLocation } from '../language/location';
99
import { getLocation } from '../language/location';
1010
import { printLocation, printSourceLocation } from '../language/printLocation';
11+
import { Maybe } from '../jsutils/Maybe';
1112

1213
/**
1314
* A GraphQLError describes an Error found during the parse, validate, or
@@ -77,11 +78,11 @@ export class GraphQLError extends Error {
7778
constructor(
7879
message: string,
7980
nodes?: ReadonlyArray<ASTNode> | ASTNode | void | null,
80-
source?: ?Source,
81-
positions?: ?ReadonlyArray<number>,
82-
path?: ?ReadonlyArray<string | number>,
83-
originalError?: ?(Error & { readonly extensions?: unknown, ... }),
84-
extensions?: ?{ [key: string]: unknown, ... },
81+
source?: Maybe<Source>,
82+
positions?: Maybe<ReadonlyArray<number>>,
83+
path?: Maybe<ReadonlyArray<string | number>>,
84+
originalError?: Maybe<(Error & { readonly extensions?: unknown, ... })>,
85+
extensions?: Maybe<{ [key: string]: unknown, ... }>,
8586
): void {
8687
super(message);
8788

src/error/locatedError.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect from '../jsutils/inspect';
2+
import { Maybe } from '../jsutils/Maybe';
23

34
import type { ASTNode } from '../language/ast';
45

@@ -12,7 +13,7 @@ import { GraphQLError } from './GraphQLError';
1213
export function locatedError(
1314
rawOriginalError: unknown,
1415
nodes: ASTNode | ReadonlyArray<ASTNode> | void | null,
15-
path?: ?ReadonlyArray<string | number>,
16+
path?: Maybe<ReadonlyArray<string | number>>,
1617
): GraphQLError {
1718
// Sometimes a non-error is thrown, wrap it as an Error instance to ensure a consistent Error interface.
1819
const originalError: Error | GraphQLError =

src/execution/execute.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
getArgumentValues,
6666
getDirectiveValues,
6767
} from './values';
68+
import { Maybe } from '../jsutils/Maybe';
6869

6970
/**
7071
* Terminology
@@ -126,12 +127,12 @@ export type FormattedExecutionResult = {
126127
export type ExecutionArgs = {
127128
schema: GraphQLSchema,
128129
document: DocumentNode,
129-
rootValue?: mixed,
130-
contextValue?: mixed,
131-
variableValues?: ?{ readonly [variable: string]: unknown, ... },
132-
operationName?: ?string,
133-
fieldResolver?: ?GraphQLFieldResolver<any, any>,
134-
typeResolver?: ?GraphQLTypeResolver<any, any>,
130+
rootValue?: unknown,
131+
contextValue?: unknown,
132+
variableValues?: Maybe<{ readonly [variable: string]: unknown, ... }>,
133+
operationName?: Maybe<string>,
134+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
135+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
135136
};
136137

137138
/**
@@ -229,7 +230,7 @@ function buildResponse(
229230
export function assertValidExecutionArguments(
230231
schema: GraphQLSchema,
231232
document: DocumentNode,
232-
rawVariableValues: ?{ readonly [variable: string]: unknown, ... },
233+
rawVariableValues: Maybe<{ readonly [variable: string]: unknown, ... }>,
233234
): void {
234235
devAssert(document, 'Must provide document.');
235236

@@ -256,10 +257,10 @@ export function buildExecutionContext(
256257
document: DocumentNode,
257258
rootValue: unknown,
258259
contextValue: unknown,
259-
rawVariableValues: ?{ readonly [variable: string]: unknown, ... },
260-
operationName: ?string,
261-
fieldResolver: ?GraphQLFieldResolver<unknown, unknown>,
262-
typeResolver?: ?GraphQLTypeResolver<unknown, unknown>,
260+
rawVariableValues: Maybe<{ readonly [variable: string]: unknown, ... }>,
261+
operationName: Maybe<string>,
262+
fieldResolver: Maybe<GraphQLFieldResolver<unknown, unknown>>,
263+
typeResolver?: Maybe<GraphQLTypeResolver<unknown, unknown>>,
263264
): ReadonlyArray<GraphQLError> | ExecutionContext {
264265
let operation: OperationDefinitionNode | void;
265266
const fragments: ObjMap<FragmentDefinitionNode> = Object.create(null);
@@ -1186,7 +1187,7 @@ export function getFieldDef(
11861187
schema: GraphQLSchema,
11871188
parentType: GraphQLObjectType,
11881189
fieldName: string,
1189-
): ?GraphQLField<unknown, unknown> {
1190+
): Maybe<GraphQLField<unknown, unknown>> {
11901191
if (
11911192
fieldName === SchemaMetaFieldDef.name &&
11921193
schema.getQueryType() === parentType

src/graphql.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { validateSchema } from './type/validate';
1515

1616
import type { ExecutionResult } from './execution/execute';
1717
import { execute } from './execution/execute';
18+
import { Maybe } from './jsutils/Maybe';
1819

1920
/**
2021
* This is the primary entry point function for fulfilling GraphQL operations
@@ -60,10 +61,10 @@ export type GraphQLArgs = {
6061
source: string | Source,
6162
rootValue?: unknown,
6263
contextValue?: unknown,
63-
variableValues?: ?{ readonly [variable: string]: unknown, ... },
64-
operationName?: ?string,
65-
fieldResolver?: ?GraphQLFieldResolver<any, any>,
66-
typeResolver?: ?GraphQLTypeResolver<any, any>,
64+
variableValues?: Maybe<{ readonly [variable: string]: unknown, ... }>,
65+
operationName?: Maybe<string>,
66+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
67+
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>,
6768
};
6869

6970
export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {

src/language/experimentalOnlineParser/onlineParser.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
GraphQLGrammarPeekConstraint,
1313
GraphQLGrammarConstraintsSet,
1414
} from './grammar';
15+
import { Maybe } from '../../jsutils/Maybe';
1516

1617
export const TokenKind = {
1718
NAME: 'Name',
@@ -86,13 +87,13 @@ export type OnlineParserState = {
8687
type Token = {
8788
kind: string,
8889
value: string,
89-
tokenName?: ?string,
90-
ruleName?: ?string,
90+
tokenName?: Maybe<string>,
91+
ruleName?: Maybe<string>,
9192
};
9293

9394
type LexerToken = {
9495
kind: string,
95-
value: ?string,
96+
value: Maybe<string>,
9697
};
9798

9899
type OnlineParserConfig = {

src/subscription/subscribe.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ import type { GraphQLFieldResolver } from '../type/definition';
2424
import { getOperationRootType } from '../utilities/getOperationRootType';
2525

2626
import mapAsyncIterator from './mapAsyncIterator';
27+
import { Maybe } from '../jsutils/Maybe';
2728

2829
export type SubscriptionArgs = {
2930
schema: GraphQLSchema,
3031
document: DocumentNode,
3132
rootValue?: unknown,
3233
contextValue?: unknown,
33-
variableValues?: ?{ readonly [variable: string]: unknown, ... },
34-
operationName?: ?string,
35-
fieldResolver?: ?GraphQLFieldResolver<any, any>,
36-
subscribeFieldResolver?: ?GraphQLFieldResolver<any, any>,
34+
variableValues?: Maybe<{ readonly [variable: string]: unknown, ... }>,
35+
operationName?: Maybe<string>,
36+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
37+
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
3738
};
3839

3940
/**
@@ -157,9 +158,9 @@ export function createSourceEventStream(
157158
document: DocumentNode,
158159
rootValue?: unknown,
159160
contextValue?: unknown,
160-
variableValues?: ?{ readonly [variable: string]: unknown, ... },
161-
operationName?: ?string,
162-
fieldResolver?: ?GraphQLFieldResolver<any, any>,
161+
variableValues?: Maybe<{ readonly [variable: string]: unknown, ... }>,
162+
operationName?: Maybe<string>,
163+
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
163164
): Promise<AsyncIterable<unknown> | ExecutionResult> {
164165
// If arguments are missing or incorrectly typed, this is an internal
165166
// developer mistake which should throw an early error.

0 commit comments

Comments
 (0)