Skip to content

Commit

Permalink
convert + (flow) to readonly (TS)
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Oct 27, 2020
1 parent 1877ca1 commit 75de44a
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 323 deletions.
16 changes: 8 additions & 8 deletions src/error/GraphQLError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,52 +35,52 @@ export class GraphQLError extends Error {
*
* Enumerable, and appears in the result of JSON.stringify().
*/
+locations: ReadonlyArray<SourceLocation> | void;
readonly locations: ReadonlyArray<SourceLocation> | void;

/**
* An array describing the JSON-path into the execution response which
* corresponds to this error. Only included for errors during execution.
*
* Enumerable, and appears in the result of JSON.stringify().
*/
+path: ReadonlyArray<string | number> | void;
readonly path: ReadonlyArray<string | number> | void;

/**
* An array of GraphQL AST Nodes corresponding to this error.
*/
+nodes: ReadonlyArray<ASTNode> | void;
readonly nodes: ReadonlyArray<ASTNode> | void;

/**
* The source GraphQL document for the first location of this 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<number> | void;
readonly positions: ReadonlyArray<number> | 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,
nodes?: ReadonlyArray<ASTNode> | ASTNode | void | null,
source?: ?Source,
positions?: ?ReadonlyArray<number>,
path?: ?ReadonlyArray<string | number>,
originalError?: ?(Error & { +extensions?: mixed, ... }),
originalError?: ?(Error & { readonly extensions?: mixed, ... }),
extensions?: ?{ [key: string]: mixed, ... },
): void {
super(message);
Expand Down
8 changes: 4 additions & 4 deletions src/error/formatError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceLocation> | void,
readonly locations: ReadonlyArray<SourceLocation> | 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<string | number> | void,
readonly path: ReadonlyArray<string | number> | 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, ... },
};
6 changes: 3 additions & 3 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
Expand Down Expand Up @@ -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.');

Expand All @@ -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<mixed, mixed>,
typeResolver?: ?GraphQLTypeResolver<mixed, mixed>,
Expand Down
4 changes: 2 additions & 2 deletions src/execution/values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CoercedVariableValues =
export function getVariableValues(
schema: GraphQLSchema,
varDefNodes: ReadonlyArray<VariableDefinitionNode>,
inputs: { +[variable: string]: mixed, ... },
inputs: { readonly [variable: string]: mixed, ... },
options?: { maxErrors?: number },
): CoercedVariableValues {
const errors = [];
Expand Down Expand Up @@ -73,7 +73,7 @@ export function getVariableValues(
function coerceVariableValues(
schema: GraphQLSchema,
varDefNodes: ReadonlyArray<VariableDefinitionNode>,
inputs: { +[variable: string]: mixed, ... },
inputs: { readonly [variable: string]: mixed, ... },
onError: (GraphQLError) => void,
): { [variable: string]: mixed, ... } {
const coercedValues = {};
Expand Down
2 changes: 1 addition & 1 deletion src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>,
typeResolver?: ?GraphQLTypeResolver<any, any>,
Expand Down
4 changes: 2 additions & 2 deletions src/jsutils/ObjMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type ObjMap<T> = { [key: string]: T, __proto__: null, ... };
export type ObjMapLike<T> = ObjMap<T> | { [key: string]: T, ... };

export type ReadOnlyObjMap<T> = { +[key: string]: T, __proto__: null, ... };
export type ReadOnlyObjMap<T> = { readonly [key: string]: T, __proto__: null, ... };
export type ReadOnlyObjMapLike<T> =
| ReadOnlyObjMap<T>
| { +[key: string]: T, ... };
| { readonly [key: string]: T, ... };
10 changes: 5 additions & 5 deletions src/jsutils/Path.ts
Original file line number Diff line number Diff line change
@@ -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<Path> | void,
prev: Readonly<Path> | void,
key: string | number,
typename: string | void,
): Path {
Expand All @@ -18,7 +18,7 @@ export function addPath(
/**
* Given a Path, return an Array of the path keys.
*/
export function pathToArray(path: ?$ReadOnly<Path>): Array<string | number> {
export function pathToArray(path: ?Readonly<Path>): Array<string | number> {
const flattened = [];
let curr = path;
while (curr) {
Expand Down
Loading

0 comments on commit 75de44a

Please sign in to comment.