22// flowlint uninitialized-instance-property:off
33
44import { isObjectLike } from '../jsutils/isObjectLike' ;
5+ import type { Maybe } from '../jsutils/Maybe' ;
56
67import type { ASTNode } from '../language/ast' ;
78import type { Source } from '../language/source' ;
@@ -35,53 +36,53 @@ export class GraphQLError extends Error {
3536 *
3637 * Enumerable, and appears in the result of JSON.stringify().
3738 */
38- + locations : $ReadOnlyArray < SourceLocation > | void ;
39+ readonly locations ?: ReadonlyArray < SourceLocation > ;
3940
4041 /**
4142 * An array describing the JSON-path into the execution response which
4243 * corresponds to this error. Only included for errors during execution.
4344 *
4445 * Enumerable, and appears in the result of JSON.stringify().
4546 */
46- + path : $ReadOnlyArray < string | number > | void ;
47+ readonly path ?: ReadonlyArray < string | number > ;
4748
4849 /**
4950 * An array of GraphQL AST Nodes corresponding to this error.
5051 */
51- + nodes : $ReadOnlyArray < ASTNode > | void ;
52+ readonly nodes ?: ReadonlyArray < ASTNode > ;
5253
5354 /**
5455 * The source GraphQL document for the first location of this error.
5556 *
5657 * Note that if this Error represents more than one node, the source may not
5758 * represent nodes after the first node.
5859 */
59- + source : Source | void ;
60+ readonly source ? : Source ;
6061
6162 /**
6263 * An array of character offsets within the source GraphQL document
6364 * which correspond to this error.
6465 */
65- + positions : $ReadOnlyArray < number > | void ;
66+ readonly positions ?: ReadonlyArray < number > ;
6667
6768 /**
6869 * The original error thrown from a field resolver during execution.
6970 */
70- + originalError : ? Error ;
71+ readonly originalError : Maybe < Error > ;
7172
7273 /**
7374 * Extension fields to add to the formatted error.
7475 */
75- + extensions : { [ key : string ] : mixed , ... } | void ;
76+ readonly extensions ? : { [ key : string ] : unknown } ;
7677
7778 constructor (
7879 message : string ,
79- nodes ?: $ReadOnlyArray < ASTNode > | ASTNode | void | null ,
80- source ?: ? Source ,
81- positions ?: ? $ReadOnlyArray < number > ,
82- path ?: ? $ReadOnlyArray < string | number > ,
83- originalError ?: ? ( Error & { + extensions ?: mixed , ... } ) ,
84- extensions ?: ? { [ key : string ] : mixed , ... } ,
80+ nodes ?: ReadonlyArray < ASTNode > | ASTNode | null ,
81+ source ?: Maybe < Source > ,
82+ positions ?: Maybe < ReadonlyArray < number > > ,
83+ path ?: Maybe < ReadonlyArray < string | number > > ,
84+ originalError ?: Maybe < Error & { readonly extensions ?: unknown } > ,
85+ extensions ?: Maybe < { [ key : string ] : unknown } > ,
8586 ) {
8687 super ( message ) ;
8788
@@ -100,8 +101,10 @@ export class GraphQLError extends Error {
100101 _source = _nodes [ 0 ] . loc ?. source ;
101102 }
102103
103- let _positions = positions ;
104- if ( ! _positions && _nodes ) {
104+ let _positions ;
105+ if ( positions ) {
106+ _positions = positions ;
107+ } else if ( _nodes ) {
105108 _positions = [ ] ;
106109 for ( const node of _nodes ) {
107110 if ( node . loc ) {
@@ -133,7 +136,6 @@ export class GraphQLError extends Error {
133136 }
134137 }
135138
136- // $FlowFixMe[cannot-write] FIXME
137139 Object . defineProperties ( this , {
138140 name : { value : 'GraphQLError' } ,
139141 message : {
@@ -212,7 +214,6 @@ export class GraphQLError extends Error {
212214 }
213215
214216 // FIXME: workaround to not break chai comparisons, should be remove in v16
215- // $FlowFixMe[unsupported-syntax] Flow doesn't support computed properties yet
216217 get [ Symbol . toStringTag ] ( ) : string {
217218 return 'Object' ;
218219 }
0 commit comments