Skip to content

Commit 6b5c8af

Browse files
igrlkIvanGoncharov
andauthored
extendSchema: preserve "description" and "extensions" (#3776)
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com> Closes #3629
1 parent 5ce7935 commit 6b5c8af

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/utilities/__tests__/extendSchema-test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ describe('extendSchema', () => {
113113
expect(extendedSchema.getDirectives()).to.have.members(specifiedDirectives);
114114
});
115115

116+
it('preserves original schema config', () => {
117+
const description = 'A schema description';
118+
const extensions = Object.freeze({ foo: 'bar' });
119+
const schema = new GraphQLSchema({ description, extensions });
120+
121+
const extendedSchema = extendSchema(schema, parse('scalar Bar'));
122+
123+
expect(extendedSchema.description).to.equal(description);
124+
expect(extendedSchema.extensions).to.deep.equal(extensions);
125+
});
126+
116127
it('extends objects by adding new fields', () => {
117128
const schema = buildSchema(`
118129
type Query {

src/utilities/extendSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,14 @@ export function extendSchemaImpl(
239239

240240
// Then produce and return a Schema config with these types.
241241
return {
242-
description: schemaDef?.description?.value,
242+
description: schemaDef?.description?.value ?? schemaConfig.description,
243243
...operationTypes,
244244
types: Object.values(typeMap),
245245
directives: [
246246
...schemaConfig.directives.map(replaceDirective),
247247
...directiveDefs.map(buildDirective),
248248
],
249-
extensions: Object.create(null),
249+
extensions: schemaConfig.extensions,
250250
astNode: schemaDef ?? schemaConfig.astNode,
251251
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExtensions),
252252
assumeValid: options?.assumeValid ?? false,

0 commit comments

Comments
 (0)