From a37b559c5c8893ee1cc04ca179479c255e9838bd Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Thu, 22 Aug 2019 11:56:05 -0700 Subject: [PATCH 1/2] Sync tstypes/errors with flow --- tstypes/error/GraphQLError.d.ts | 33 +++++++++++++++++++++------------ tstypes/error/formatError.d.ts | 2 +- tstypes/error/index.d.ts | 3 +-- tstypes/error/locatedError.d.ts | 2 +- tstypes/error/printError.d.ts | 7 ------- 5 files changed, 24 insertions(+), 23 deletions(-) delete mode 100644 tstypes/error/printError.d.ts diff --git a/tstypes/error/GraphQLError.d.ts b/tstypes/error/GraphQLError.d.ts index 948007b547..29becde279 100644 --- a/tstypes/error/GraphQLError.d.ts +++ b/tstypes/error/GraphQLError.d.ts @@ -1,8 +1,8 @@ import Maybe from '../tsutils/Maybe'; -import { getLocation } from '../language'; + import { ASTNode } from '../language/ast'; import { Source } from '../language/source'; -import { SourceLocation } from '../language/location'; +import { SourceLocation, getLocation } from '../language/location'; /** * A GraphQLError describes an Error found during the parse, validate, or @@ -11,6 +11,16 @@ import { SourceLocation } from '../language/location'; * GraphQL document and/or execution result that correspond to the Error. */ export class GraphQLError extends Error { + constructor( + message: string, + nodes?: ReadonlyArray | ASTNode | undefined, + source?: Maybe, + positions?: Maybe>, + path?: Maybe>, + originalError?: Maybe, + extensions?: Maybe<{ [key: string]: any }>, + ); + /** * A message describing the Error for debugging purposes. * @@ -47,6 +57,9 @@ export class GraphQLError extends Error { /** * The source GraphQL document corresponding to this error. + * + * Note that if this Error represents more than one node, the source may not + * represent nodes after the first node. */ readonly source: Source | undefined; @@ -65,14 +78,10 @@ export class GraphQLError extends Error { * Extension fields to add to the formatted error. */ readonly extensions: { [key: string]: any } | undefined; - - constructor( - message: string, - nodes?: ReadonlyArray | ASTNode | undefined, - source?: Maybe, - positions?: Maybe>, - path?: Maybe>, - originalError?: Maybe, - extensions?: Maybe<{ [key: string]: any }>, - ); } + +/** + * Prints a GraphQLError to a string, representing useful location information + * about the error's position in the source. + */ +export function printError(error: GraphQLError): string; diff --git a/tstypes/error/formatError.d.ts b/tstypes/error/formatError.d.ts index ce2a206b4e..484c241e2b 100644 --- a/tstypes/error/formatError.d.ts +++ b/tstypes/error/formatError.d.ts @@ -1,5 +1,5 @@ -import { GraphQLError } from './GraphQLError'; import { SourceLocation } from '../language/location'; +import { GraphQLError } from './GraphQLError'; /** * Given a GraphQLError, format it according to the rules described by the diff --git a/tstypes/error/index.d.ts b/tstypes/error/index.d.ts index b43bcdee00..9373b7167d 100644 --- a/tstypes/error/index.d.ts +++ b/tstypes/error/index.d.ts @@ -1,5 +1,4 @@ -export { GraphQLError } from './GraphQLError'; +export { GraphQLError, printError } from './GraphQLError'; export { syntaxError } from './syntaxError'; export { locatedError } from './locatedError'; -export { printError } from './printError'; export { formatError, GraphQLFormattedError } from './formatError'; diff --git a/tstypes/error/locatedError.d.ts b/tstypes/error/locatedError.d.ts index 8573638680..0adda83777 100644 --- a/tstypes/error/locatedError.d.ts +++ b/tstypes/error/locatedError.d.ts @@ -1,5 +1,5 @@ -import { GraphQLError } from './GraphQLError'; import { ASTNode } from '../language/ast'; +import { GraphQLError } from './GraphQLError'; /** * Given an arbitrary Error, presumably thrown while attempting to execute a diff --git a/tstypes/error/printError.d.ts b/tstypes/error/printError.d.ts deleted file mode 100644 index d3a2036be6..0000000000 --- a/tstypes/error/printError.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { GraphQLError } from './GraphQLError'; - -/** - * Prints a GraphQLError to a string, representing useful location information - * about the error's position in the source. - */ -export function printError(error: GraphQLError): string; From e726c10302c566f5aa59fc0dcf9ba4bb32c3d88c Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Thu, 22 Aug 2019 11:58:08 -0700 Subject: [PATCH 2/2] Add .d.ts comments to flow --- src/error/formatError.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/error/formatError.js b/src/error/formatError.js index c0c055dca5..a3616e8a67 100644 --- a/src/error/formatError.js +++ b/src/error/formatError.js @@ -22,9 +22,31 @@ export function formatError(error: GraphQLError): GraphQLFormattedError { : { message, locations, path }; } +/** + * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors + */ 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 + * localization. + */ +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, + /** + * 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, + /** + * 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, ... }, |};