@@ -82,10 +82,51 @@ export class GraphQLError extends Error {
8282 * Extension fields to add to the formatted error.
8383 */
8484 readonly extensions : { [ key : string ] : any } ;
85+
86+ toString ( ) : string ;
87+
88+ toJSON ( ) : GraphQLFormattedError ;
8589}
8690
8791/**
8892 * Prints a GraphQLError to a string, representing useful location information
8993 * about the error's position in the source.
9094 */
9195export function printError ( error : GraphQLError ) : string ;
96+
97+ /**
98+ * Given a GraphQLError, format it according to the rules described by the
99+ * Response Format, Errors section of the GraphQL Specification.
100+ */
101+ export function formatError ( error : GraphQLError ) : GraphQLFormattedError ;
102+
103+ /**
104+ * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
105+ */
106+ export interface GraphQLFormattedError <
107+ TExtensions extends Record < string , any > = Record < string , any >
108+ > {
109+ /**
110+ * A short, human-readable summary of the problem that **SHOULD NOT** change
111+ * from occurrence to occurrence of the problem, except for purposes of
112+ * localization.
113+ */
114+ readonly message : string ;
115+ /**
116+ * If an error can be associated to a particular point in the requested
117+ * GraphQL document, it should contain a list of locations.
118+ */
119+ readonly locations ?: ReadonlyArray < SourceLocation > ;
120+ /**
121+ * If an error can be associated to a particular field in the GraphQL result,
122+ * it _must_ contain an entry with the key `path` that details the path of
123+ * the response field which experienced the error. This allows clients to
124+ * identify whether a null result is intentional or caused by a runtime error.
125+ */
126+ readonly path ?: ReadonlyArray < string | number > ;
127+ /**
128+ * Reserved for implementors to extend the protocol however they see fit,
129+ * and hence there are no additional restrictions on its contents.
130+ */
131+ readonly extensions ?: TExtensions ;
132+ }
0 commit comments