Skip to content

Commit 39b69da

Browse files
Flow: switched to exact object by default (#3085)
In preparation for TS migration
1 parent 6fd5607 commit 39b69da

33 files changed

+264
-266
lines changed

.eslintrc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ overrides:
464464
flowtype/no-unused-expressions: off
465465
flowtype/no-weak-types: [error, { any: false }]
466466
flowtype/require-compound-type-alias: off
467-
flowtype/require-exact-type: off
467+
flowtype/require-exact-type: [error, never]
468468
flowtype/require-indexer-name: error
469469
flowtype/require-inexact-type: off # checked by Flow
470470
flowtype/require-parameter-type: off

.flowconfig

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
[include]
66

77
[lints]
8-
sketchy-null-bool=error
9-
sketchy-null-string=error
10-
sketchy-null-number=error
11-
sketchy-null-mixed=error
8+
sketchy-null=error
129
sketchy-number=error
1310
untyped-type-import=error
1411
nonstrict-import=off
@@ -20,8 +17,8 @@ unsafe-getters-setters=error
2017
unnecessary-optional-chain=error
2118
unnecessary-invariant=error
2219
signature-verification-failure=error
23-
implicit-inexact-object=error
24-
ambiguous-object-type=error
20+
implicit-inexact-object=off
21+
ambiguous-object-type=off
2522
uninitialized-instance-property=error
2623
default-import-access=error
2724
invalid-import-star-use=error
@@ -33,6 +30,7 @@ export-renamed-default=error
3330
[options]
3431
all=true
3532
module.use_strict=true
33+
exact_by_default=true
3634
experimental.const_params=true
3735
include_warnings=true
3836
no_flowlib=true

src/__testUtils__/__tests__/genFuzzStrings-test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { describe, it } from 'mocha';
33

44
import { genFuzzStrings } from '../genFuzzStrings';
55

6-
function expectFuzzStrings(options: {|
6+
function expectFuzzStrings(options: {
77
allowedChars: Array<string>,
88
maxLength: number,
9-
|}) {
9+
}) {
1010
return expect([...genFuzzStrings(options)]);
1111
}
1212

src/__testUtils__/genFuzzStrings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Generator that produces all possible combinations of allowed characters.
33
*/
4-
export function* genFuzzStrings(options: {|
4+
export function* genFuzzStrings(options: {
55
allowedChars: Array<string>,
66
maxLength: number,
7-
|}): Generator<string, void, void> {
7+
}): Generator<string, void, void> {
88
const { allowedChars, maxLength } = options;
99
const numAllowedChars = allowedChars.length;
1010

src/__tests__/starWarsData.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ export type Character = {
1010
...
1111
};
1212

13-
export type Human = {|
13+
export type Human = {
1414
type: 'Human',
1515
id: string,
1616
name: string,
1717
friends: Array<string>,
1818
appearsIn: Array<number>,
1919
homePlanet?: string,
20-
|};
20+
};
2121

22-
export type Droid = {|
22+
export type Droid = {
2323
type: 'Droid',
2424
id: string,
2525
name: string,
2626
friends: Array<string>,
2727
appearsIn: Array<number>,
2828
primaryFunction: string,
29-
|};
29+
};
3030

3131
/**
3232
* This defines a basic set of data for our Star Wars Schema.
@@ -79,7 +79,7 @@ const tarkin: Human = {
7979
appearsIn: [4],
8080
};
8181

82-
const humanData: {| [id: string]: Human |} = {
82+
const humanData: { [id: string]: Human } = {
8383
[luke.id]: luke,
8484
[vader.id]: vader,
8585
[han.id]: han,
@@ -105,7 +105,7 @@ const artoo: Droid = {
105105
primaryFunction: 'Astromech',
106106
};
107107

108-
const droidData: {| [id: string]: Droid |} = {
108+
const droidData: { [id: string]: Droid } = {
109109
[threepio.id]: threepio,
110110
[artoo.id]: artoo,
111111
};

src/error/formatError.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function formatError(error: GraphQLError): GraphQLFormattedError {
2323
/**
2424
* @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
2525
*/
26-
export type GraphQLFormattedError = {|
26+
export type GraphQLFormattedError = {
2727
/**
2828
* A short, human-readable summary of the problem that **SHOULD NOT** change
2929
* from occurrence to occurrence of the problem, except for purposes of
@@ -47,4 +47,4 @@ export type GraphQLFormattedError = {|
4747
* and hence there are no additional restrictions on its contents.
4848
*/
4949
+extensions?: { [key: string]: mixed, ... },
50-
|};
50+
};

src/execution/__tests__/abstract-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { buildSchema } from '../../utilities/buildASTSchema';
1717

1818
import { executeSync, execute } from '../execute';
1919

20-
async function executeQuery(args: {|
20+
async function executeQuery(args: {
2121
schema: GraphQLSchema,
2222
query: string,
2323
rootValue?: mixed,
24-
|}) {
24+
}) {
2525
const { schema, query, rootValue } = args;
2626
const document = parse(query);
2727
const result = executeSync({
@@ -534,7 +534,7 @@ describe('Execute: Handles execution of abstract types', () => {
534534
}
535535
`);
536536

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

src/execution/__tests__/lists-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -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: mixed, as: string }) {
6969
const { listField, as } = args;
7070
const schema = buildSchema(`type Query { listField: ${as} }`);
7171
const document = parse('{ listField }');

src/execution/__tests__/resolve-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('Execute: resolve function', () => {
6464
this._num = num;
6565
}
6666

67-
test(args: {| addend1: number |}, context: {| addend2: number |}) {
67+
test(args: { addend1: number }, context: { addend2: number }) {
6868
return this._num + args.addend1 + context.addend2;
6969
}
7070
}

src/execution/execute.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import {
9292
* Namely, schema of the type system that is currently executing,
9393
* and the fragments defined in the query document
9494
*/
95-
export type ExecutionContext = {|
95+
export type ExecutionContext = {
9696
schema: GraphQLSchema,
9797
fragments: ObjMap<FragmentDefinitionNode>,
9898
rootValue: mixed,
@@ -102,7 +102,7 @@ export type ExecutionContext = {|
102102
fieldResolver: GraphQLFieldResolver<any, any>,
103103
typeResolver: GraphQLTypeResolver<any, any>,
104104
errors: Array<GraphQLError>,
105-
|};
105+
};
106106

107107
/**
108108
* The result of GraphQL execution.
@@ -111,19 +111,19 @@ export type ExecutionContext = {|
111111
* - `data` is the result of a successful execution of the query.
112112
* - `extensions` is reserved for adding non-standard properties.
113113
*/
114-
export type ExecutionResult = {|
114+
export type ExecutionResult = {
115115
errors?: $ReadOnlyArray<GraphQLError>,
116116
data?: ObjMap<mixed> | null,
117117
extensions?: ObjMap<mixed>,
118-
|};
118+
};
119119

120-
export type FormattedExecutionResult = {|
120+
export type FormattedExecutionResult = {
121121
errors?: $ReadOnlyArray<GraphQLFormattedError>,
122122
data?: ObjMap<mixed> | null,
123123
extensions?: ObjMap<mixed>,
124-
|};
124+
};
125125

126-
export type ExecutionArgs = {|
126+
export type ExecutionArgs = {
127127
schema: GraphQLSchema,
128128
document: DocumentNode,
129129
rootValue?: mixed,
@@ -132,7 +132,7 @@ export type ExecutionArgs = {|
132132
operationName?: ?string,
133133
fieldResolver?: ?GraphQLFieldResolver<any, any>,
134134
typeResolver?: ?GraphQLTypeResolver<any, any>,
135-
|};
135+
};
136136

137137
/**
138138
* Implements the "Evaluating requests" section of the GraphQL specification.

src/execution/values.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { valueFromAST } from '../utilities/valueFromAST';
2323
import { coerceInputValue } from '../utilities/coerceInputValue';
2424

2525
type CoercedVariableValues =
26-
| {| errors: $ReadOnlyArray<GraphQLError> |}
27-
| {| coerced: { [variable: string]: mixed, ... } |};
26+
| { errors: $ReadOnlyArray<GraphQLError> }
27+
| { coerced: { [variable: string]: mixed, ... } };
2828

2929
/**
3030
* Prepares an object map of variableValues of the correct type based on the
@@ -41,7 +41,7 @@ export function getVariableValues(
4141
schema: GraphQLSchema,
4242
varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
4343
inputs: { +[variable: string]: mixed, ... },
44-
options?: {| maxErrors?: number |},
44+
options?: { maxErrors?: number },
4545
): CoercedVariableValues {
4646
const errors = [];
4747
const maxErrors = options?.maxErrors;

src/graphql.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { execute } from './execution/execute';
5555
* If not provided, the default type resolver is used (which looks for a
5656
* `__typename` field or alternatively calls the `isTypeOf` method).
5757
*/
58-
export type GraphQLArgs = {|
58+
export type GraphQLArgs = {
5959
schema: GraphQLSchema,
6060
source: string | Source,
6161
rootValue?: mixed,
@@ -64,7 +64,7 @@ export type GraphQLArgs = {|
6464
operationName?: ?string,
6565
fieldResolver?: ?GraphQLFieldResolver<any, any>,
6666
typeResolver?: ?GraphQLTypeResolver<any, any>,
67-
|};
67+
};
6868

6969
export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {
7070
// Always return a Promise for a consistent API.

src/jsutils/Path.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export type Path = {|
1+
export type Path = {
22
+prev: Path | void,
33
+key: string | number,
44
+typename: string | void,
5-
|};
5+
};
66

77
/**
88
* Given a Path and a key, return a new Path containing the new key.

src/language/__tests__/source-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Source', () => {
2525
});
2626

2727
it('rejects invalid locationOffset', () => {
28-
function createSource(locationOffset: {| line: number, column: number |}) {
28+
function createSource(locationOffset: { line: number, column: number }) {
2929
return new Source('', '', locationOffset);
3030
}
3131

0 commit comments

Comments
 (0)