From 1e4b5fa28837f1c1d1341ab0170f6fdcd64447b7 Mon Sep 17 00:00:00 2001 From: Jed Mao Date: Sun, 16 Jun 2019 02:32:21 -0500 Subject: [PATCH] Update GraphQLFormattedError (#36205) --- types/graphql/error/formatError.d.ts | 34 ++++++++++++++++++++++++---- types/graphql/index.d.ts | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/types/graphql/error/formatError.d.ts b/types/graphql/error/formatError.d.ts index 2d87c877a9..18fa94d6b7 100644 --- a/types/graphql/error/formatError.d.ts +++ b/types/graphql/error/formatError.d.ts @@ -7,9 +7,33 @@ import { SourceLocation } from "../language/location"; */ export function formatError(error: GraphQLError): GraphQLFormattedError; -export interface GraphQLFormattedError { - readonly message: string; - readonly locations: ReadonlyArray | undefined; - readonly path: ReadonlyArray | undefined; - readonly extensions?: { [key: string]: any }; +/** + * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors + */ +export interface GraphQLFormattedError< + TExtensions extends Record = Record +> { + /** + * A short, human-readable summary of the problem that **SHOULD NOT** change + * from occurrence to occurrence of the problem, except for purposes of + * localization. + */ + 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. + */ + readonly locations?: ReadonlyArray + /** + * 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. + */ + readonly path?: ReadonlyArray + /** + * Reserved for implementors to extend the protocol however they see fit, + * and hence there are no additional restrictions on its contents. + */ + readonly extensions?: TExtensions } diff --git a/types/graphql/index.d.ts b/types/graphql/index.d.ts index d152dba8c5..d27b723cba 100644 --- a/types/graphql/index.d.ts +++ b/types/graphql/index.d.ts @@ -19,6 +19,7 @@ // Pavel Lang // Mark Caudill // Martijn Walraven +// Jed Mao // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6