Skip to content

Commit 0f0a31c

Browse files
committed
Reflect defaultErrorBehavior in buildClientSchema
1 parent 64a9162 commit 0f0a31c

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/utilities/__tests__/buildClientSchema-test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
GraphQLString,
1919
} from '../../type/scalars';
2020
import { GraphQLSchema } from '../../type/schema';
21+
import { validateSchema } from '../../type/validate';
2122

2223
import { graphqlSync } from '../../graphql';
2324

@@ -158,6 +159,26 @@ describe('Type System: build schema from introspection', () => {
158159
expect(clientSchema.getType('ID')).to.equal(undefined);
159160
});
160161

162+
it('reflects defaultErrorBehavior', () => {
163+
const schema = buildSchema(`
164+
schema @behavior(onError: NO_PROPAGATE) {
165+
query: Query
166+
}
167+
type Query {
168+
foo: String
169+
}
170+
`);
171+
const introspection = introspectionFromSchema(schema, {
172+
errorBehavior: true,
173+
});
174+
const clientSchema = buildClientSchema(introspection);
175+
176+
expect(clientSchema.defaultErrorBehavior).to.equal('NO_PROPAGATE');
177+
178+
const errors = validateSchema(clientSchema);
179+
expect(errors).to.have.length(0);
180+
});
181+
161182
it('builds a schema with a recursive type reference', () => {
162183
const sdl = dedent`
163184
schema {

src/utilities/buildClientSchema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export function buildClientSchema(
108108
? schemaIntrospection.directives.map(buildDirective)
109109
: [];
110110

111+
const defaultErrorBehavior = schemaIntrospection.defaultErrorBehavior;
112+
111113
// Then produce and return a Schema with these types.
112114
return new GraphQLSchema({
113115
description: schemaIntrospection.description,
@@ -116,6 +118,7 @@ export function buildClientSchema(
116118
subscription: subscriptionType,
117119
types: Object.values(typeMap),
118120
directives,
121+
defaultErrorBehavior,
119122
assumeValid: options?.assumeValid,
120123
});
121124

src/utilities/getIntrospectionQuery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Maybe } from '../jsutils/Maybe';
22

3+
import type { GraphQLErrorBehavior } from '../error/ErrorBehavior';
4+
35
import type { DirectiveLocation } from '../language/directiveLocation';
46

57
export interface IntrospectionOptions {
@@ -206,6 +208,7 @@ export interface IntrospectionSchema {
206208
>;
207209
readonly types: ReadonlyArray<IntrospectionType>;
208210
readonly directives: ReadonlyArray<IntrospectionDirective>;
211+
readonly defaultErrorBehavior?: Maybe<GraphQLErrorBehavior>;
209212
}
210213

211214
export type IntrospectionType =

0 commit comments

Comments
 (0)