Skip to content

Commit

Permalink
extendSchema: preserve "description" and "extensions" (#3776)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Goncharov <ivan.goncharov.ua@gmail.com>
Closes #3629
  • Loading branch information
igrlk authored Nov 21, 2022
1 parent 5ce7935 commit 6b5c8af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/utilities/__tests__/extendSchema-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ describe('extendSchema', () => {
expect(extendedSchema.getDirectives()).to.have.members(specifiedDirectives);
});

it('preserves original schema config', () => {
const description = 'A schema description';
const extensions = Object.freeze({ foo: 'bar' });
const schema = new GraphQLSchema({ description, extensions });

const extendedSchema = extendSchema(schema, parse('scalar Bar'));

expect(extendedSchema.description).to.equal(description);
expect(extendedSchema.extensions).to.deep.equal(extensions);
});

it('extends objects by adding new fields', () => {
const schema = buildSchema(`
type Query {
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/extendSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ export function extendSchemaImpl(

// Then produce and return a Schema config with these types.
return {
description: schemaDef?.description?.value,
description: schemaDef?.description?.value ?? schemaConfig.description,
...operationTypes,
types: Object.values(typeMap),
directives: [
...schemaConfig.directives.map(replaceDirective),
...directiveDefs.map(buildDirective),
],
extensions: Object.create(null),
extensions: schemaConfig.extensions,
astNode: schemaDef ?? schemaConfig.astNode,
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExtensions),
assumeValid: options?.assumeValid ?? false,
Expand Down

0 comments on commit 6b5c8af

Please sign in to comment.