From 75de44ae6847b9369946f2fe4e40018e9a573140 Mon Sep 17 00:00:00 2001 From: saihaj Date: Tue, 20 Oct 2020 15:29:55 -0500 Subject: [PATCH] convert `+` (flow) to `readonly` (TS) --- src/error/GraphQLError.ts | 16 +- src/error/formatError.ts | 8 +- src/execution/execute.ts | 6 +- src/execution/values.ts | 4 +- src/graphql.ts | 2 +- src/jsutils/ObjMap.ts | 4 +- src/jsutils/Path.ts | 10 +- src/language/ast.ts | 420 +++++++++--------- src/language/location.ts | 4 +- src/language/visitor.ts | 2 +- src/subscription/subscribe.ts | 4 +- src/type/__tests__/enumType-test.ts | 2 +- src/type/definition.ts | 20 +- src/type/validate.ts | 8 +- .../__tests__/buildASTSchema-test.ts | 2 +- src/utilities/__tests__/extendSchema-test.ts | 2 +- src/utilities/getIntrospectionQuery.ts | 118 ++--- src/utilities/lexicographicSortSchema.ts | 2 +- src/utilities/printSchema.ts | 2 +- src/validation/ValidationContext.ts | 6 +- .../rules/UniqueFieldDefinitionNamesRule.ts | 4 +- 21 files changed, 323 insertions(+), 323 deletions(-) diff --git a/src/error/GraphQLError.ts b/src/error/GraphQLError.ts index 020c1d3abd1..c4026354083 100644 --- a/src/error/GraphQLError.ts +++ b/src/error/GraphQLError.ts @@ -35,7 +35,7 @@ export class GraphQLError extends Error { * * Enumerable, and appears in the result of JSON.stringify(). */ - +locations: ReadonlyArray | void; + readonly locations: ReadonlyArray | void; /** * An array describing the JSON-path into the execution response which @@ -43,12 +43,12 @@ export class GraphQLError extends Error { * * Enumerable, and appears in the result of JSON.stringify(). */ - +path: ReadonlyArray | void; + readonly path: ReadonlyArray | void; /** * An array of GraphQL AST Nodes corresponding to this error. */ - +nodes: ReadonlyArray | void; + readonly nodes: ReadonlyArray | void; /** * The source GraphQL document for the first location of this error. @@ -56,23 +56,23 @@ export class GraphQLError extends Error { * Note that if this Error represents more than one node, the source may not * represent nodes after the first node. */ - +source: Source | void; + readonly source: Source | void; /** * An array of character offsets within the source GraphQL document * which correspond to this error. */ - +positions: ReadonlyArray | void; + readonly positions: ReadonlyArray | void; /** * The original error thrown from a field resolver during execution. */ - +originalError: ?Error; + readonly originalError: ?Error; /** * Extension fields to add to the formatted error. */ - +extensions: { [key: string]: mixed, ... } | void; + readonly extensions: { [key: string]: mixed, ... } | void; constructor( message: string, @@ -80,7 +80,7 @@ export class GraphQLError extends Error { source?: ?Source, positions?: ?ReadonlyArray, path?: ?ReadonlyArray, - originalError?: ?(Error & { +extensions?: mixed, ... }), + originalError?: ?(Error & { readonly extensions?: mixed, ... }), extensions?: ?{ [key: string]: mixed, ... }, ): void { super(message); diff --git a/src/error/formatError.ts b/src/error/formatError.ts index ba3dfe11ba8..b12ff9a131e 100644 --- a/src/error/formatError.ts +++ b/src/error/formatError.ts @@ -29,22 +29,22 @@ export type GraphQLFormattedError = { * from occurrence to occurrence of the problem, except for purposes of * localization. */ - +message: string, + readonly message: string, /** * If an error can be associated to a particular point in the requested * GraphQL document, it should contain a list of locations. */ - +locations: ReadonlyArray | void, + readonly locations: ReadonlyArray | void, /** * If an error can be associated to a particular field in the GraphQL result, * it _must_ contain an entry with the key `path` that details the path of * the response field which experienced the error. This allows clients to * identify whether a null result is intentional or caused by a runtime error. */ - +path: ReadonlyArray | void, + readonly path: ReadonlyArray | void, /** * Reserved for implementors to extend the protocol however they see fit, * and hence there are no additional restrictions on its contents. */ - +extensions?: { [key: string]: mixed, ... }, + readonly extensions?: { [key: string]: mixed, ... }, }; diff --git a/src/execution/execute.ts b/src/execution/execute.ts index aaf1d978173..562b5c2c35e 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -128,7 +128,7 @@ export type ExecutionArgs = { document: DocumentNode, rootValue?: mixed, contextValue?: mixed, - variableValues?: ?{ +[variable: string]: mixed, ... }, + variableValues?: ?{ readonly [variable: string]: mixed, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, typeResolver?: ?GraphQLTypeResolver, @@ -229,7 +229,7 @@ function buildResponse( export function assertValidExecutionArguments( schema: GraphQLSchema, document: DocumentNode, - rawVariableValues: ?{ +[variable: string]: mixed, ... }, + rawVariableValues: ?{ readonly [variable: string]: mixed, ... }, ): void { devAssert(document, 'Must provide document.'); @@ -256,7 +256,7 @@ export function buildExecutionContext( document: DocumentNode, rootValue: mixed, contextValue: mixed, - rawVariableValues: ?{ +[variable: string]: mixed, ... }, + rawVariableValues: ?{ readonly [variable: string]: mixed, ... }, operationName: ?string, fieldResolver: ?GraphQLFieldResolver, typeResolver?: ?GraphQLTypeResolver, diff --git a/src/execution/values.ts b/src/execution/values.ts index 22ea9ce83a9..63f3bdbca80 100644 --- a/src/execution/values.ts +++ b/src/execution/values.ts @@ -40,7 +40,7 @@ type CoercedVariableValues = export function getVariableValues( schema: GraphQLSchema, varDefNodes: ReadonlyArray, - inputs: { +[variable: string]: mixed, ... }, + inputs: { readonly [variable: string]: mixed, ... }, options?: { maxErrors?: number }, ): CoercedVariableValues { const errors = []; @@ -73,7 +73,7 @@ export function getVariableValues( function coerceVariableValues( schema: GraphQLSchema, varDefNodes: ReadonlyArray, - inputs: { +[variable: string]: mixed, ... }, + inputs: { readonly [variable: string]: mixed, ... }, onError: (GraphQLError) => void, ): { [variable: string]: mixed, ... } { const coercedValues = {}; diff --git a/src/graphql.ts b/src/graphql.ts index c96bb93103e..a7b224c08be 100644 --- a/src/graphql.ts +++ b/src/graphql.ts @@ -60,7 +60,7 @@ export type GraphQLArgs = { source: string | Source, rootValue?: mixed, contextValue?: mixed, - variableValues?: ?{ +[variable: string]: mixed, ... }, + variableValues?: ?{ readonly [variable: string]: mixed, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, typeResolver?: ?GraphQLTypeResolver, diff --git a/src/jsutils/ObjMap.ts b/src/jsutils/ObjMap.ts index 9b6ef5e16e5..d3c1ef89e46 100644 --- a/src/jsutils/ObjMap.ts +++ b/src/jsutils/ObjMap.ts @@ -1,7 +1,7 @@ export type ObjMap = { [key: string]: T, __proto__: null, ... }; export type ObjMapLike = ObjMap | { [key: string]: T, ... }; -export type ReadOnlyObjMap = { +[key: string]: T, __proto__: null, ... }; +export type ReadOnlyObjMap = { readonly [key: string]: T, __proto__: null, ... }; export type ReadOnlyObjMapLike = | ReadOnlyObjMap - | { +[key: string]: T, ... }; + | { readonly [key: string]: T, ... }; diff --git a/src/jsutils/Path.ts b/src/jsutils/Path.ts index f7888ae027f..2770343580f 100644 --- a/src/jsutils/Path.ts +++ b/src/jsutils/Path.ts @@ -1,14 +1,14 @@ export type Path = { - +prev: Path | void, - +key: string | number, - +typename: string | void, + readonly prev: Path | void, + readonly key: string | number, + readonly typename: string | void, }; /** * Given a Path and a key, return a new Path containing the new key. */ export function addPath( - prev: $ReadOnly | void, + prev: Readonly | void, key: string | number, typename: string | void, ): Path { @@ -18,7 +18,7 @@ export function addPath( /** * Given a Path, return an Array of the path keys. */ -export function pathToArray(path: ?$ReadOnly): Array { +export function pathToArray(path: ?Readonly): Array { const flattened = []; let curr = path; while (curr) { diff --git a/src/language/ast.ts b/src/language/ast.ts index 0417c1af82b..a81f1743371 100644 --- a/src/language/ast.ts +++ b/src/language/ast.ts @@ -9,27 +9,27 @@ export class Location { /** * The character offset at which this Node begins. */ - +start: number; + readonly start: number; /** * The character offset at which this Node ends. */ - +end: number; + readonly end: number; /** * The Token at which this Node begins. */ - +startToken: Token; + readonly startToken: Token; /** * The Token at which this Node ends. */ - +endToken: Token; + readonly endToken: Token; /** * The Source document the AST represents. */ - +source: Source; + readonly source: Source; constructor(startToken: Token, endToken: Token, source: Source) { this.start = startToken.start; @@ -58,40 +58,40 @@ export class Token { /** * The kind of Token. */ - +kind: TokenKindEnum; + readonly kind: TokenKindEnum; /** * The character offset at which this Node begins. */ - +start: number; + readonly start: number; /** * The character offset at which this Node ends. */ - +end: number; + readonly end: number; /** * The 1-indexed line number on which this Token appears. */ - +line: number; + readonly line: number; /** * The 1-indexed column number at which this Token begins. */ - +column: number; + readonly column: number; /** * For non-punctuation tokens, represents the interpreted value of the token. */ - +value: string | void; + readonly value: string | void; /** * Tokens exist as nodes in a double-linked-list amongst all tokens * including ignored tokens. is always the first node and * the last. */ - +prev: Token | null; - +next: Token | null; + readonly prev: Token | null; + readonly next: Token | null; constructor( kind: TokenKindEnum, @@ -240,17 +240,17 @@ export type ASTKindToNode = { // Name export type NameNode = { - +kind: 'Name', - +loc?: Location, - +value: string, + readonly kind: 'Name', + readonly loc?: Location, + readonly value: string, }; // Document export type DocumentNode = { - +kind: 'Document', - +loc?: Location, - +definitions: ReadonlyArray, + readonly kind: 'Document', + readonly loc?: Location, + readonly definitions: ReadonlyArray, }; export type DefinitionNode = @@ -263,30 +263,30 @@ export type ExecutableDefinitionNode = | FragmentDefinitionNode; export type OperationDefinitionNode = { - +kind: 'OperationDefinition', - +loc?: Location, - +operation: OperationTypeNode, - +name?: NameNode, - +variableDefinitions?: ReadonlyArray, - +directives?: ReadonlyArray, - +selectionSet: SelectionSetNode, + readonly kind: 'OperationDefinition', + readonly loc?: Location, + readonly operation: OperationTypeNode, + readonly name?: NameNode, + readonly variableDefinitions?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly selectionSet: SelectionSetNode, }; export type OperationTypeNode = 'query' | 'mutation' | 'subscription'; export type VariableDefinitionNode = { - +kind: 'VariableDefinition', - +loc?: Location, - +variable: VariableNode, - +type: TypeNode, - +defaultValue?: ValueNode, - +directives?: ReadonlyArray, + readonly kind: 'VariableDefinition', + readonly loc?: Location, + readonly variable: VariableNode, + readonly type: TypeNode, + readonly defaultValue?: ValueNode, + readonly directives?: ReadonlyArray, }; export type VariableNode = { - +kind: 'Variable', - +loc?: Location, - +name: NameNode, + readonly kind: 'Variable', + readonly loc?: Location, + readonly name: NameNode, }; export type SelectionSetNode = { @@ -298,49 +298,49 @@ export type SelectionSetNode = { export type SelectionNode = FieldNode | FragmentSpreadNode | InlineFragmentNode; export type FieldNode = { - +kind: 'Field', - +loc?: Location, - +alias?: NameNode, - +name: NameNode, - +arguments?: ReadonlyArray, - +directives?: ReadonlyArray, - +selectionSet?: SelectionSetNode, + readonly kind: 'Field', + readonly loc?: Location, + readonly alias?: NameNode, + readonly name: NameNode, + readonly arguments?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly selectionSet?: SelectionSetNode, }; export type ArgumentNode = { - +kind: 'Argument', - +loc?: Location, - +name: NameNode, - +value: ValueNode, + readonly kind: 'Argument', + readonly loc?: Location, + readonly name: NameNode, + readonly value: ValueNode, }; // Fragments export type FragmentSpreadNode = { - +kind: 'FragmentSpread', - +loc?: Location, - +name: NameNode, - +directives?: ReadonlyArray, + readonly kind: 'FragmentSpread', + readonly loc?: Location, + readonly name: NameNode, + readonly directives?: ReadonlyArray, }; export type InlineFragmentNode = { - +kind: 'InlineFragment', - +loc?: Location, - +typeCondition?: NamedTypeNode, - +directives?: ReadonlyArray, - +selectionSet: SelectionSetNode, + readonly kind: 'InlineFragment', + readonly loc?: Location, + readonly typeCondition?: NamedTypeNode, + readonly directives?: ReadonlyArray, + readonly selectionSet: SelectionSetNode, }; export type FragmentDefinitionNode = { - +kind: 'FragmentDefinition', - +loc?: Location, - +name: NameNode, + readonly kind: 'FragmentDefinition', + readonly loc?: Location, + readonly name: NameNode, // Note: fragment variable definitions are experimental and may be changed // or removed in the future. - +variableDefinitions?: ReadonlyArray, - +typeCondition: NamedTypeNode, - +directives?: ReadonlyArray, - +selectionSet: SelectionSetNode, + readonly variableDefinitions?: ReadonlyArray, + readonly typeCondition: NamedTypeNode, + readonly directives?: ReadonlyArray, + readonly selectionSet: SelectionSetNode, }; // Values @@ -357,67 +357,67 @@ export type ValueNode = | ObjectValueNode; export type IntValueNode = { - +kind: 'IntValue', - +loc?: Location, - +value: string, + readonly kind: 'IntValue', + readonly loc?: Location, + readonly value: string, }; export type FloatValueNode = { - +kind: 'FloatValue', - +loc?: Location, - +value: string, + readonly kind: 'FloatValue', + readonly loc?: Location, + readonly value: string, }; export type StringValueNode = { - +kind: 'StringValue', - +loc?: Location, - +value: string, - +block?: boolean, + readonly kind: 'StringValue', + readonly loc?: Location, + readonly value: string, + readonly block?: boolean, }; export type BooleanValueNode = { - +kind: 'BooleanValue', - +loc?: Location, - +value: boolean, + readonly kind: 'BooleanValue', + readonly loc?: Location, + readonly value: boolean, }; export type NullValueNode = { - +kind: 'NullValue', - +loc?: Location, + readonly kind: 'NullValue', + readonly loc?: Location, }; export type EnumValueNode = { - +kind: 'EnumValue', - +loc?: Location, - +value: string, + readonly kind: 'EnumValue', + readonly loc?: Location, + readonly value: string, }; export type ListValueNode = { - +kind: 'ListValue', - +loc?: Location, - +values: ReadonlyArray, + readonly kind: 'ListValue', + readonly loc?: Location, + readonly values: ReadonlyArray, }; export type ObjectValueNode = { - +kind: 'ObjectValue', - +loc?: Location, - +fields: ReadonlyArray, + readonly kind: 'ObjectValue', + readonly loc?: Location, + readonly fields: ReadonlyArray, }; export type ObjectFieldNode = { - +kind: 'ObjectField', - +loc?: Location, - +name: NameNode, - +value: ValueNode, + readonly kind: 'ObjectField', + readonly loc?: Location, + readonly name: NameNode, + readonly value: ValueNode, }; // Directives export type DirectiveNode = { - +kind: 'Directive', - +loc?: Location, - +name: NameNode, - +arguments?: ReadonlyArray, + readonly kind: 'Directive', + readonly loc?: Location, + readonly name: NameNode, + readonly arguments?: ReadonlyArray, }; // Type Reference @@ -425,21 +425,21 @@ export type DirectiveNode = { export type TypeNode = NamedTypeNode | ListTypeNode | NonNullTypeNode; export type NamedTypeNode = { - +kind: 'NamedType', - +loc?: Location, - +name: NameNode, + readonly kind: 'NamedType', + readonly loc?: Location, + readonly name: NameNode, }; export type ListTypeNode = { - +kind: 'ListType', - +loc?: Location, - +type: TypeNode, + readonly kind: 'ListType', + readonly loc?: Location, + readonly type: TypeNode, }; export type NonNullTypeNode = { - +kind: 'NonNullType', - +loc?: Location, - +type: NamedTypeNode | ListTypeNode, + readonly kind: 'NonNullType', + readonly loc?: Location, + readonly type: NamedTypeNode | ListTypeNode, }; // Type System Definition @@ -450,18 +450,18 @@ export type TypeSystemDefinitionNode = | DirectiveDefinitionNode; export type SchemaDefinitionNode = { - +kind: 'SchemaDefinition', - +loc?: Location, - +description?: StringValueNode, - +directives?: ReadonlyArray, - +operationTypes: ReadonlyArray, + readonly kind: 'SchemaDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly directives?: ReadonlyArray, + readonly operationTypes: ReadonlyArray, }; export type OperationTypeDefinitionNode = { - +kind: 'OperationTypeDefinition', - +loc?: Location, - +operation: OperationTypeNode, - +type: NamedTypeNode, + readonly kind: 'OperationTypeDefinition', + readonly loc?: Location, + readonly operation: OperationTypeNode, + readonly type: NamedTypeNode, }; // Type Definition @@ -475,98 +475,98 @@ export type TypeDefinitionNode = | InputObjectTypeDefinitionNode; export type ScalarTypeDefinitionNode = { - +kind: 'ScalarTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +directives?: ReadonlyArray, + readonly kind: 'ScalarTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly directives?: ReadonlyArray, }; export type ObjectTypeDefinitionNode = { - +kind: 'ObjectTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +interfaces?: ReadonlyArray, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'ObjectTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly interfaces?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; export type FieldDefinitionNode = { - +kind: 'FieldDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +arguments?: ReadonlyArray, - +type: TypeNode, - +directives?: ReadonlyArray, + readonly kind: 'FieldDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly arguments?: ReadonlyArray, + readonly type: TypeNode, + readonly directives?: ReadonlyArray, }; export type InputValueDefinitionNode = { - +kind: 'InputValueDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +type: TypeNode, - +defaultValue?: ValueNode, - +directives?: ReadonlyArray, + readonly kind: 'InputValueDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly type: TypeNode, + readonly defaultValue?: ValueNode, + readonly directives?: ReadonlyArray, }; export type InterfaceTypeDefinitionNode = { - +kind: 'InterfaceTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +interfaces?: ReadonlyArray, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'InterfaceTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly interfaces?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; export type UnionTypeDefinitionNode = { - +kind: 'UnionTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +directives?: ReadonlyArray, - +types?: ReadonlyArray, + readonly kind: 'UnionTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly types?: ReadonlyArray, }; export type EnumTypeDefinitionNode = { - +kind: 'EnumTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +directives?: ReadonlyArray, - +values?: ReadonlyArray, + readonly kind: 'EnumTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly values?: ReadonlyArray, }; export type EnumValueDefinitionNode = { - +kind: 'EnumValueDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +directives?: ReadonlyArray, + readonly kind: 'EnumValueDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly directives?: ReadonlyArray, }; export type InputObjectTypeDefinitionNode = { - +kind: 'InputObjectTypeDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'InputObjectTypeDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; // Directive Definitions export type DirectiveDefinitionNode = { - +kind: 'DirectiveDefinition', - +loc?: Location, - +description?: StringValueNode, - +name: NameNode, - +arguments?: ReadonlyArray, - +repeatable: boolean, - +locations: ReadonlyArray, + readonly kind: 'DirectiveDefinition', + readonly loc?: Location, + readonly description?: StringValueNode, + readonly name: NameNode, + readonly arguments?: ReadonlyArray, + readonly repeatable: boolean, + readonly locations: ReadonlyArray, }; // Type System Extensions @@ -574,10 +574,10 @@ export type DirectiveDefinitionNode = { export type TypeSystemExtensionNode = SchemaExtensionNode | TypeExtensionNode; export type SchemaExtensionNode = { - +kind: 'SchemaExtension', - +loc?: Location, - +directives?: ReadonlyArray, - +operationTypes?: ReadonlyArray, + readonly kind: 'SchemaExtension', + readonly loc?: Location, + readonly directives?: ReadonlyArray, + readonly operationTypes?: ReadonlyArray, }; // Type Extensions @@ -591,50 +591,50 @@ export type TypeExtensionNode = | InputObjectTypeExtensionNode; export type ScalarTypeExtensionNode = { - +kind: 'ScalarTypeExtension', - +loc?: Location, - +name: NameNode, - +directives?: ReadonlyArray, + readonly kind: 'ScalarTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly directives?: ReadonlyArray, }; export type ObjectTypeExtensionNode = { - +kind: 'ObjectTypeExtension', - +loc?: Location, - +name: NameNode, - +interfaces?: ReadonlyArray, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'ObjectTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly interfaces?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; export type InterfaceTypeExtensionNode = { - +kind: 'InterfaceTypeExtension', - +loc?: Location, - +name: NameNode, - +interfaces?: ReadonlyArray, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'InterfaceTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly interfaces?: ReadonlyArray, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; export type UnionTypeExtensionNode = { - +kind: 'UnionTypeExtension', - +loc?: Location, - +name: NameNode, - +directives?: ReadonlyArray, - +types?: ReadonlyArray, + readonly kind: 'UnionTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly types?: ReadonlyArray, }; export type EnumTypeExtensionNode = { - +kind: 'EnumTypeExtension', - +loc?: Location, - +name: NameNode, - +directives?: ReadonlyArray, - +values?: ReadonlyArray, + readonly kind: 'EnumTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly values?: ReadonlyArray, }; export type InputObjectTypeExtensionNode = { - +kind: 'InputObjectTypeExtension', - +loc?: Location, - +name: NameNode, - +directives?: ReadonlyArray, - +fields?: ReadonlyArray, + readonly kind: 'InputObjectTypeExtension', + readonly loc?: Location, + readonly name: NameNode, + readonly directives?: ReadonlyArray, + readonly fields?: ReadonlyArray, }; diff --git a/src/language/location.ts b/src/language/location.ts index 4695d52e71b..716145bf2b2 100644 --- a/src/language/location.ts +++ b/src/language/location.ts @@ -4,8 +4,8 @@ import type { Source } from './source'; * Represents a location in a Source. */ export type SourceLocation = { - +line: number, - +column: number, + readonly line: number, + readonly column: number, }; /** diff --git a/src/language/visitor.ts b/src/language/visitor.ts index 29368552f2c..f5f6bf8b59f 100644 --- a/src/language/visitor.ts +++ b/src/language/visitor.ts @@ -17,7 +17,7 @@ export type Visitor> = KindToNode, (Node) => VisitFn | EnterLeave>, >; -type EnterLeave = { +enter?: T, +leave?: T }; +type EnterLeave = { readonly enter?: T, readonly leave?: T }; type ShapeMap = $Shape<$ObjMap>; /** diff --git a/src/subscription/subscribe.ts b/src/subscription/subscribe.ts index fc658b71ca5..631c2997009 100644 --- a/src/subscription/subscribe.ts +++ b/src/subscription/subscribe.ts @@ -30,7 +30,7 @@ export type SubscriptionArgs = { document: DocumentNode, rootValue?: mixed, contextValue?: mixed, - variableValues?: ?{ +[variable: string]: mixed, ... }, + variableValues?: ?{ readonly [variable: string]: mixed, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, subscribeFieldResolver?: ?GraphQLFieldResolver, @@ -157,7 +157,7 @@ export function createSourceEventStream( document: DocumentNode, rootValue?: mixed, contextValue?: mixed, - variableValues?: ?{ +[variable: string]: mixed, ... }, + variableValues?: ?{ readonly [variable: string]: mixed, ... }, operationName?: ?string, fieldResolver?: ?GraphQLFieldResolver, ): Promise | ExecutionResult> { diff --git a/src/type/__tests__/enumType-test.ts b/src/type/__tests__/enumType-test.ts index 0145657733f..4d232794469 100644 --- a/src/type/__tests__/enumType-test.ts +++ b/src/type/__tests__/enumType-test.ts @@ -114,7 +114,7 @@ const schema = new GraphQLSchema({ function executeQuery( source: string, - variableValues?: { +[variable: string]: mixed, ... }, + variableValues?: { readonly [variable: string]: mixed, ... }, ) { return graphqlSync({ schema, source, variableValues }); } diff --git a/src/type/definition.ts b/src/type/definition.ts index df0f1da16e8..8ae0576927b 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -917,16 +917,16 @@ export type GraphQLFieldResolver< ) => mixed; export type GraphQLResolveInfo = { - +fieldName: string, - +fieldNodes: ReadonlyArray, - +returnType: GraphQLOutputType, - +parentType: GraphQLObjectType, - +path: Path, - +schema: GraphQLSchema, - +fragments: ObjMap, - +rootValue: mixed, - +operation: OperationDefinitionNode, - +variableValues: { [variable: string]: mixed, ... }, + readonly fieldName: string, + readonly fieldNodes: ReadonlyArray, + readonly returnType: GraphQLOutputType, + readonly parentType: GraphQLObjectType, + readonly path: Path, + readonly schema: GraphQLSchema, + readonly fragments: ObjMap, + readonly rootValue: mixed, + readonly operation: OperationDefinitionNode, + readonly variableValues: { [variable: string]: mixed, ... }, }; export type GraphQLFieldConfig< diff --git a/src/type/validate.ts b/src/type/validate.ts index 4e6acec77f0..d02ef133662 100644 --- a/src/type/validate.ts +++ b/src/type/validate.ts @@ -83,8 +83,8 @@ export function assertValidSchema(schema: GraphQLSchema): void { } class SchemaValidationContext { - +_errors: Array; - +schema: GraphQLSchema; + readonly _errors: Array; + readonly schema: GraphQLSchema; constructor(schema) { this._errors = []; @@ -200,7 +200,7 @@ function validateDirectives(context: SchemaValidationContext): void { function validateName( context: SchemaValidationContext, - node: { +name: string, +astNode: ?ASTNode, ... }, + node: { readonly name: string, readonly astNode: ?ASTNode, ... }, ): void { // Ensure names are valid, however introspection types opt out. const error = isValidNameError(node.name); @@ -659,7 +659,7 @@ function getUnionMemberTypeNodes( } function getDeprecatedDirectiveNode( - definitionNode: ?{ +directives?: ReadonlyArray, ... }, + definitionNode: ?{ readonly directives?: ReadonlyArray, ... }, ): ?DirectiveNode { // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') return definitionNode?.directives?.find( diff --git a/src/utilities/__tests__/buildASTSchema-test.ts b/src/utilities/__tests__/buildASTSchema-test.ts index cb1794bd7af..863871ba5ad 100644 --- a/src/utilities/__tests__/buildASTSchema-test.ts +++ b/src/utilities/__tests__/buildASTSchema-test.ts @@ -51,7 +51,7 @@ function cycleSDL(sdl: string): string { return printSchema(buildSchema(sdl)); } -function printASTNode(obj: ?{ +astNode: ?ASTNode, ... }): string { +function printASTNode(obj: ?{ readonly astNode: ?ASTNode, ... }): string { invariant(obj?.astNode != null); return print(obj.astNode); } diff --git a/src/utilities/__tests__/extendSchema-test.ts b/src/utilities/__tests__/extendSchema-test.ts index 64ac885c4bd..b58734e0cd5 100644 --- a/src/utilities/__tests__/extendSchema-test.ts +++ b/src/utilities/__tests__/extendSchema-test.ts @@ -59,7 +59,7 @@ function printSchemaChanges( }); } -function printASTNode(obj: ?{ +astNode: ?ASTNode, ... }): string { +function printASTNode(obj: ?{ readonly astNode: ?ASTNode, ... }): string { invariant(obj?.astNode != null); return print(obj.astNode); } diff --git a/src/utilities/getIntrospectionQuery.ts b/src/utilities/getIntrospectionQuery.ts index 464a8260fba..7264d4068f1 100644 --- a/src/utilities/getIntrospectionQuery.ts +++ b/src/utilities/getIntrospectionQuery.ts @@ -137,16 +137,16 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string { } export type IntrospectionQuery = { - +__schema: IntrospectionSchema, + readonly __schema: IntrospectionSchema, }; export type IntrospectionSchema = { - +description?: ?string, - +queryType: IntrospectionNamedTypeRef, - +mutationType: ?IntrospectionNamedTypeRef, - +subscriptionType: ?IntrospectionNamedTypeRef, - +types: ReadonlyArray, - +directives: ReadonlyArray, + readonly description?: ?string, + readonly queryType: IntrospectionNamedTypeRef, + readonly mutationType: ?IntrospectionNamedTypeRef, + readonly subscriptionType: ?IntrospectionNamedTypeRef, + readonly types: ReadonlyArray, + readonly directives: ReadonlyArray, }; export type IntrospectionType = @@ -170,70 +170,70 @@ export type IntrospectionInputType = | IntrospectionInputObjectType; export type IntrospectionScalarType = { - +kind: 'SCALAR', - +name: string, - +description?: ?string, - +specifiedByUrl?: ?string, + readonly kind: 'SCALAR', + readonly name: string, + readonly description?: ?string, + readonly specifiedByUrl?: ?string, }; export type IntrospectionObjectType = { - +kind: 'OBJECT', - +name: string, - +description?: ?string, - +fields: ReadonlyArray, - +interfaces: ReadonlyArray< + readonly kind: 'OBJECT', + readonly name: string, + readonly description?: ?string, + readonly fields: ReadonlyArray, + readonly interfaces: ReadonlyArray< IntrospectionNamedTypeRef, >, }; export type IntrospectionInterfaceType = { - +kind: 'INTERFACE', - +name: string, - +description?: ?string, - +fields: ReadonlyArray, - +interfaces: ReadonlyArray< + readonly kind: 'INTERFACE', + readonly name: string, + readonly description?: ?string, + readonly fields: ReadonlyArray, + readonly interfaces: ReadonlyArray< IntrospectionNamedTypeRef, >, - +possibleTypes: ReadonlyArray< + readonly possibleTypes: ReadonlyArray< IntrospectionNamedTypeRef, >, }; export type IntrospectionUnionType = { - +kind: 'UNION', - +name: string, - +description?: ?string, - +possibleTypes: ReadonlyArray< + readonly kind: 'UNION', + readonly name: string, + readonly description?: ?string, + readonly possibleTypes: ReadonlyArray< IntrospectionNamedTypeRef, >, }; export type IntrospectionEnumType = { - +kind: 'ENUM', - +name: string, - +description?: ?string, - +enumValues: ReadonlyArray, + readonly kind: 'ENUM', + readonly name: string, + readonly description?: ?string, + readonly enumValues: ReadonlyArray, }; export type IntrospectionInputObjectType = { - +kind: 'INPUT_OBJECT', - +name: string, - +description?: ?string, - +inputFields: ReadonlyArray, + readonly kind: 'INPUT_OBJECT', + readonly name: string, + readonly description?: ?string, + readonly inputFields: ReadonlyArray, }; export type IntrospectionListTypeRef< T: IntrospectionTypeRef = IntrospectionTypeRef, > = { - +kind: 'LIST', - +ofType: T, + readonly kind: 'LIST', + readonly ofType: T, }; export type IntrospectionNonNullTypeRef< T: IntrospectionTypeRef = IntrospectionTypeRef, > = { - +kind: 'NON_NULL', - +ofType: T, + readonly kind: 'NON_NULL', + readonly ofType: T, }; export type IntrospectionTypeRef = @@ -262,37 +262,37 @@ export type IntrospectionInputTypeRef = export type IntrospectionNamedTypeRef< T: IntrospectionType = IntrospectionType, > = { - +kind: $PropertyType, - +name: string, + readonly kind: $PropertyType, + readonly name: string, }; export type IntrospectionField = { - +name: string, - +description?: ?string, - +args: ReadonlyArray, - +type: IntrospectionOutputTypeRef, - +isDeprecated: boolean, - +deprecationReason: ?string, + readonly name: string, + readonly description?: ?string, + readonly args: ReadonlyArray, + readonly type: IntrospectionOutputTypeRef, + readonly isDeprecated: boolean, + readonly deprecationReason: ?string, }; export type IntrospectionInputValue = { - +name: string, - +description?: ?string, - +type: IntrospectionInputTypeRef, - +defaultValue: ?string, + readonly name: string, + readonly description?: ?string, + readonly type: IntrospectionInputTypeRef, + readonly defaultValue: ?string, }; export type IntrospectionEnumValue = { - +name: string, - +description?: ?string, - +isDeprecated: boolean, - +deprecationReason: ?string, + readonly name: string, + readonly description?: ?string, + readonly isDeprecated: boolean, + readonly deprecationReason: ?string, }; export type IntrospectionDirective = { - +name: string, - +description?: ?string, - +isRepeatable?: boolean, - +locations: ReadonlyArray, - +args: ReadonlyArray, + readonly name: string, + readonly description?: ?string, + readonly isRepeatable?: boolean, + readonly locations: ReadonlyArray, + readonly args: ReadonlyArray, }; diff --git a/src/utilities/lexicographicSortSchema.ts b/src/utilities/lexicographicSortSchema.ts index 4e706f48fd4..c7d9efab6fe 100644 --- a/src/utilities/lexicographicSortSchema.ts +++ b/src/utilities/lexicographicSortSchema.ts @@ -167,7 +167,7 @@ function sortObjMap(map: ObjMap, sortValueFn?: (T) => R): ObjMap { return sortedMap; } -function sortByName( +function sortByName( array: ReadonlyArray, ): Array { return sortBy(array, (obj) => obj.name); diff --git a/src/utilities/printSchema.ts b/src/utilities/printSchema.ts index dc61205d308..14cdcdb3a3a 100644 --- a/src/utilities/printSchema.ts +++ b/src/utilities/printSchema.ts @@ -306,7 +306,7 @@ function printSpecifiedByUrl(scalar: GraphQLScalarType): string { } function printDescription( - def: { +description: ?string, ... }, + def: { readonly description: ?string, ... }, indentation: string = '', firstInBlock: boolean = true, ): string { diff --git a/src/validation/ValidationContext.ts b/src/validation/ValidationContext.ts index 0323021129f..5d10009f3fd 100644 --- a/src/validation/ValidationContext.ts +++ b/src/validation/ValidationContext.ts @@ -30,9 +30,9 @@ import { TypeInfo, visitWithTypeInfo } from '../utilities/TypeInfo'; type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode; type VariableUsage = { - +node: VariableNode, - +type: ?GraphQLInputType, - +defaultValue: ?mixed, + readonly node: VariableNode, + readonly type: ?GraphQLInputType, + readonly defaultValue: ?mixed, }; /** diff --git a/src/validation/rules/UniqueFieldDefinitionNamesRule.ts b/src/validation/rules/UniqueFieldDefinitionNamesRule.ts index b90c1daa37d..c45fb781f2c 100644 --- a/src/validation/rules/UniqueFieldDefinitionNamesRule.ts +++ b/src/validation/rules/UniqueFieldDefinitionNamesRule.ts @@ -38,8 +38,8 @@ export function UniqueFieldDefinitionNamesRule( }; function checkFieldUniqueness(node: { - +name: NameNode, - +fields?: ReadonlyArray, + readonly name: NameNode, + readonly fields?: ReadonlyArray, ... }) { const typeName = node.name.value;