@@ -31,6 +31,8 @@ import {
31
31
import type { GraphQLDirective } from './directives' ;
32
32
import { isDirective , specifiedDirectives } from './directives' ;
33
33
import { __Schema } from './introspection' ;
34
+ import type { GraphQLErrorBehavior } from '../error' ;
35
+ import { isErrorBehavior } from '../error/ErrorBehavior' ;
34
36
35
37
/**
36
38
* Test if the given value is a GraphQL schema.
@@ -129,6 +131,8 @@ export interface GraphQLSchemaExtensions {
129
131
*/
130
132
export class GraphQLSchema {
131
133
description : Maybe < string > ;
134
+ /** @experimental */
135
+ readonly defaultErrorBehavior : GraphQLErrorBehavior ;
132
136
extensions : Readonly < GraphQLSchemaExtensions > ;
133
137
astNode : Maybe < SchemaDefinitionNode > ;
134
138
extensionASTNodes : ReadonlyArray < SchemaExtensionNode > ;
@@ -163,8 +167,15 @@ export class GraphQLSchema {
163
167
'"directives" must be Array if provided but got: ' +
164
168
`${ inspect ( config . directives ) } .` ,
165
169
) ;
170
+ devAssert (
171
+ ! config . defaultErrorBehavior ||
172
+ isErrorBehavior ( config . defaultErrorBehavior ) ,
173
+ '"defaultErrorBehavior" must be one of "NO_PROPAGATE", "PROPAGATE" or "ABORT", but got: ' +
174
+ `${ inspect ( config . defaultErrorBehavior ) } .` ,
175
+ ) ;
166
176
167
177
this . description = config . description ;
178
+ this . defaultErrorBehavior = config . defaultErrorBehavior ?? 'PROPAGATE' ;
168
179
this . extensions = toObjMap ( config . extensions ) ;
169
180
this . astNode = config . astNode ;
170
181
this . extensionASTNodes = config . extensionASTNodes ?? [ ] ;
@@ -386,6 +397,20 @@ export interface GraphQLSchemaConfig extends GraphQLSchemaValidationOptions {
386
397
subscription ?: Maybe < GraphQLObjectType > ;
387
398
types ?: Maybe < ReadonlyArray < GraphQLNamedType > > ;
388
399
directives ?: Maybe < ReadonlyArray < GraphQLDirective > > ;
400
+ /**
401
+ * Experimental. Defines the default GraphQL error behavior when the
402
+ * GraphQLArgs does not include an `onError` property.
403
+ *
404
+ * Set to NO_PROPAGATE if your schema only needs to support modern
405
+ * "error-handling" clients.
406
+ *
407
+ * It is not recommended to set this to ABORT.
408
+ *
409
+ * Default: PROPAGATE
410
+ *
411
+ * @experimental
412
+ */
413
+ defaultErrorBehavior ?: GraphQLErrorBehavior ;
389
414
extensions ?: Maybe < Readonly < GraphQLSchemaExtensions > > ;
390
415
astNode ?: Maybe < SchemaDefinitionNode > ;
391
416
extensionASTNodes ?: Maybe < ReadonlyArray < SchemaExtensionNode > > ;
0 commit comments