Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extendSchema: preserve "description" and "extensions" #3776

Merged

Conversation

igrlk
Copy link

@igrlk igrlk commented Nov 13, 2022

👋

Closes #3629

Current behavior:

When calling extendSchema(schema, schemaModification), extended schema description is calculated as schemaDef?.description?.value, where

  • schemaDef is a nullable schema definition, that will not be null only if schemaModification declares the type schema (it happens only when we call buildSchema or call extendSchema(schema, 'extend type __Schema { ... }'))
  • schemaDef?.description is not undefined only when extendSchema is called from buildSchema, otherwise it's undefined because we don't allow a construction like:
"my awesome description" // error - graphql-js doesn't allow you to set the description when you extend schema
extend type __Schema { ... }

As a result, every extendSchema call besides the one in buildSchema will cause description to become undefined

Proposed solution:

Always fallback to the original schema description:
description: schemaDef?.description?.value ?? schemaConfig.description

It will allow us to make sure that we take a description from schemaDef when schema is being built and take original schema description in any other cases

@netlify
Copy link

netlify bot commented Nov 13, 2022

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 5693423
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/637b709375931b0008ef6d75
😎 Deploy Preview https://deploy-preview-3776--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

Hi @igrlk, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@saihaj saihaj requested a review from a team November 14, 2022 10:34
@IvanGoncharov
Copy link
Member

Hi @igrlk
Thank you for this PR, I also noticed that we have the exact same problem with extensions so I fixed it in the same PR.

@IvanGoncharov IvanGoncharov added the PR: bug fix 🐞 requires increase of "patch" version number label Nov 21, 2022
@IvanGoncharov IvanGoncharov changed the title Copy original schema description to extended schema when calling "extendSchema" extendSchema: preserve "description" and "extensions" Nov 21, 2022
@IvanGoncharov IvanGoncharov merged commit 6b5c8af into graphql:main Nov 21, 2022
@igrlk
Copy link
Author

igrlk commented Nov 21, 2022

Thank you, @IvanGoncharov!

@igrlk igrlk deleted the copy-schema-description-in-extend-schema branch November 21, 2022 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bug fix 🐞 requires increase of "patch" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

extendSchema() doesn't set GraphQLSchema.description in some cases
2 participants