Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow: switched to exact object by default #3085

Merged
merged 1 commit into from May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.yml
Expand Up @@ -464,7 +464,7 @@ overrides:
flowtype/no-unused-expressions: off
flowtype/no-weak-types: [error, { any: false }]
flowtype/require-compound-type-alias: off
flowtype/require-exact-type: off
flowtype/require-exact-type: [error, never]
flowtype/require-indexer-name: error
flowtype/require-inexact-type: off # checked by Flow
flowtype/require-parameter-type: off
Expand Down
10 changes: 4 additions & 6 deletions .flowconfig
Expand Up @@ -5,10 +5,7 @@
[include]

[lints]
sketchy-null-bool=error
sketchy-null-string=error
sketchy-null-number=error
sketchy-null-mixed=error
sketchy-null=error
sketchy-number=error
untyped-type-import=error
nonstrict-import=off
Expand All @@ -20,8 +17,8 @@ unsafe-getters-setters=error
unnecessary-optional-chain=error
unnecessary-invariant=error
signature-verification-failure=error
implicit-inexact-object=error
ambiguous-object-type=error
implicit-inexact-object=off
ambiguous-object-type=off
uninitialized-instance-property=error
default-import-access=error
invalid-import-star-use=error
Expand All @@ -33,6 +30,7 @@ export-renamed-default=error
[options]
all=true
module.use_strict=true
exact_by_default=true
experimental.const_params=true
include_warnings=true
no_flowlib=true
Expand Down
4 changes: 2 additions & 2 deletions src/__testUtils__/__tests__/genFuzzStrings-test.js
Expand Up @@ -3,10 +3,10 @@ import { describe, it } from 'mocha';

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

function expectFuzzStrings(options: {|
function expectFuzzStrings(options: {
allowedChars: Array<string>,
maxLength: number,
|}) {
}) {
return expect([...genFuzzStrings(options)]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/__testUtils__/genFuzzStrings.js
@@ -1,10 +1,10 @@
/**
* Generator that produces all possible combinations of allowed characters.
*/
export function* genFuzzStrings(options: {|
export function* genFuzzStrings(options: {
allowedChars: Array<string>,
maxLength: number,
|}): Generator<string, void, void> {
}): Generator<string, void, void> {
const { allowedChars, maxLength } = options;
const numAllowedChars = allowedChars.length;

Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/starWarsData.js
Expand Up @@ -10,23 +10,23 @@ export type Character = {
...
};

export type Human = {|
export type Human = {
type: 'Human',
id: string,
name: string,
friends: Array<string>,
appearsIn: Array<number>,
homePlanet?: string,
|};
};

export type Droid = {|
export type Droid = {
type: 'Droid',
id: string,
name: string,
friends: Array<string>,
appearsIn: Array<number>,
primaryFunction: string,
|};
};

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

const humanData: {| [id: string]: Human |} = {
const humanData: { [id: string]: Human } = {
[luke.id]: luke,
[vader.id]: vader,
[han.id]: han,
Expand All @@ -105,7 +105,7 @@ const artoo: Droid = {
primaryFunction: 'Astromech',
};

const droidData: {| [id: string]: Droid |} = {
const droidData: { [id: string]: Droid } = {
[threepio.id]: threepio,
[artoo.id]: artoo,
};
Expand Down
4 changes: 2 additions & 2 deletions src/error/formatError.js
Expand Up @@ -23,7 +23,7 @@ export function formatError(error: GraphQLError): GraphQLFormattedError {
/**
* @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
*/
export type GraphQLFormattedError = {|
export type GraphQLFormattedError = {
/**
* A short, human-readable summary of the problem that **SHOULD NOT** change
* from occurrence to occurrence of the problem, except for purposes of
Expand All @@ -47,4 +47,4 @@ export type GraphQLFormattedError = {|
* and hence there are no additional restrictions on its contents.
*/
+extensions?: { [key: string]: mixed, ... },
|};
};
6 changes: 3 additions & 3 deletions src/execution/__tests__/abstract-test.js
Expand Up @@ -17,11 +17,11 @@ import { buildSchema } from '../../utilities/buildASTSchema';

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

async function executeQuery(args: {|
async function executeQuery(args: {
schema: GraphQLSchema,
query: string,
rootValue?: mixed,
|}) {
}) {
const { schema, query, rootValue } = args;
const document = parse(query);
const result = executeSync({
Expand Down Expand Up @@ -534,7 +534,7 @@ describe('Execute: Handles execution of abstract types', () => {
}
`);

function expectError({ forTypeName }: {| forTypeName: mixed |}) {
function expectError({ forTypeName }: { forTypeName: mixed }) {
const rootValue = { pet: { __typename: forTypeName } };
const result = executeSync({ schema, document, rootValue });
return {
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/lists-test.js
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: mixed, as: string }) {
const { listField, as } = args;
const schema = buildSchema(`type Query { listField: ${as} }`);
const document = parse('{ listField }');
Expand Down
2 changes: 1 addition & 1 deletion src/execution/__tests__/resolve-test.js
Expand Up @@ -64,7 +64,7 @@ describe('Execute: resolve function', () => {
this._num = num;
}

test(args: {| addend1: number |}, context: {| addend2: number |}) {
test(args: { addend1: number }, context: { addend2: number }) {
return this._num + args.addend1 + context.addend2;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/execution/execute.js
Expand Up @@ -92,7 +92,7 @@ import {
* Namely, schema of the type system that is currently executing,
* and the fragments defined in the query document
*/
export type ExecutionContext = {|
export type ExecutionContext = {
schema: GraphQLSchema,
fragments: ObjMap<FragmentDefinitionNode>,
rootValue: mixed,
Expand All @@ -102,7 +102,7 @@ export type ExecutionContext = {|
fieldResolver: GraphQLFieldResolver<any, any>,
typeResolver: GraphQLTypeResolver<any, any>,
errors: Array<GraphQLError>,
|};
};

/**
* The result of GraphQL execution.
Expand All @@ -111,19 +111,19 @@ export type ExecutionContext = {|
* - `data` is the result of a successful execution of the query.
* - `extensions` is reserved for adding non-standard properties.
*/
export type ExecutionResult = {|
export type ExecutionResult = {
errors?: $ReadOnlyArray<GraphQLError>,
data?: ObjMap<mixed> | null,
extensions?: ObjMap<mixed>,
|};
};

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

export type ExecutionArgs = {|
export type ExecutionArgs = {
schema: GraphQLSchema,
document: DocumentNode,
rootValue?: mixed,
Expand All @@ -132,7 +132,7 @@ export type ExecutionArgs = {|
operationName?: ?string,
fieldResolver?: ?GraphQLFieldResolver<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
|};
};

/**
* Implements the "Evaluating requests" section of the GraphQL specification.
Expand Down
6 changes: 3 additions & 3 deletions src/execution/values.js
Expand Up @@ -23,8 +23,8 @@ import { valueFromAST } from '../utilities/valueFromAST';
import { coerceInputValue } from '../utilities/coerceInputValue';

type CoercedVariableValues =
| {| errors: $ReadOnlyArray<GraphQLError> |}
| {| coerced: { [variable: string]: mixed, ... } |};
| { errors: $ReadOnlyArray<GraphQLError> }
| { coerced: { [variable: string]: mixed, ... } };

/**
* Prepares an object map of variableValues of the correct type based on the
Expand All @@ -41,7 +41,7 @@ export function getVariableValues(
schema: GraphQLSchema,
varDefNodes: $ReadOnlyArray<VariableDefinitionNode>,
inputs: { +[variable: string]: mixed, ... },
options?: {| maxErrors?: number |},
options?: { maxErrors?: number },
): CoercedVariableValues {
const errors = [];
const maxErrors = options?.maxErrors;
Expand Down
4 changes: 2 additions & 2 deletions src/graphql.js
Expand Up @@ -55,7 +55,7 @@ import { execute } from './execution/execute';
* If not provided, the default type resolver is used (which looks for a
* `__typename` field or alternatively calls the `isTypeOf` method).
*/
export type GraphQLArgs = {|
export type GraphQLArgs = {
schema: GraphQLSchema,
source: string | Source,
rootValue?: mixed,
Expand All @@ -64,7 +64,7 @@ export type GraphQLArgs = {|
operationName?: ?string,
fieldResolver?: ?GraphQLFieldResolver<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
|};
};

export function graphql(args: GraphQLArgs): Promise<ExecutionResult> {
// Always return a Promise for a consistent API.
Expand Down
4 changes: 2 additions & 2 deletions src/jsutils/Path.js
@@ -1,8 +1,8 @@
export type Path = {|
export type Path = {
+prev: Path | void,
+key: string | number,
+typename: string | void,
|};
};

/**
* Given a Path and a key, return a new Path containing the new key.
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/source-test.js
Expand Up @@ -25,7 +25,7 @@ describe('Source', () => {
});

it('rejects invalid locationOffset', () => {
function createSource(locationOffset: {| line: number, column: number |}) {
function createSource(locationOffset: { line: number, column: number }) {
return new Source('', '', locationOffset);
}

Expand Down