Skip to content

fix: reload schema when a change to the schema file is detected - #3216

Merged
acao merged 4 commits into
mainfrom
unknown repository
Jun 20, 2023
Merged

acao merged 4 commits into
mainfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Jun 7, 2023

Copy link
Copy Markdown

Summay

Currently, the schema is cached permanently and never reloaded. This makes it very awkward when you're developing the graphql api and the front-end at the same time, as the auto completion and validation will rely on incorrect data.

Notes

I found a function named _invalidateSchemaCacheForProject that did what I needed, however it's not actually used anywhere. I assume this was removed by accident, so I found somewhere I think is appropriate to invoke it.

Changes

  • Invalidate the schema cache when changed in handleWatchedFilesChangedNotification
  • Add .json to watched files so it will pick up changes to introspection files

@changeset-bot

changeset-bot Bot commented Jun 7, 2023 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 108e77f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
graphql-language-service-server Patch
vscode-graphql Patch
graphql-language-service-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 7, 2023 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@acao

acao commented Jun 11, 2023

Copy link
Copy Markdown
Contributor

@simowe awesome work! have you tested this with both URL schema and file schema?

also, please add a changeset summarizing the work as per the bot comment

lastly, there is one failing test, if you can try to fix it locally

@ghost ghost changed the title Fix: invalidate schema when it changes fix: reload schema when a change to the schema file is detected Jun 20, 2023
// These ignore node_modules and .git by default
workspace.createFileSystemWatcher(
'**/{*.graphql,*.graphqls,*.gql,*.js,*.mjs,*.cjs,*.esm,*.es,*.es6,*.jsx,*.ts,*.tsx,*.vue,*.svelte,*.cts,*.mts}',
'**/{*.graphql,*.graphqls,*.gql,*.js,*.mjs,*.cjs,*.esm,*.es,*.es6,*.jsx,*.ts,*.tsx,*.vue,*.svelte,*.cts,*.mts,*.json}',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'**/{*.graphql,*.graphqls,*.gql,*.js,*.mjs,*.cjs,*.esm,*.es,*.es6,*.jsx,*.ts,*.tsx,*.vue,*.svelte,*.cts,*.mts,*.json}',
'**/*.{graphql,graphqls,gql,js,mjs,cjs,esm,es,es6,jsx,ts,tsx,vue,svelte,cts,mts,json}',

@acao I think this can be simplified to ?

@dimaMachina dimaMachina Jun 20, 2023 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also es, esm and es6 extension should be removed 😅 never saw that somebody use it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'**/{*.graphql,*.graphqls,*.gql,*.js,*.mjs,*.cjs,*.esm,*.es,*.es6,*.jsx,*.ts,*.tsx,*.vue,*.svelte,*.cts,*.mts,*.json}',
'**/*.{graphql,graphqls,gql,js,mjs,cjs,jsx,ts,tsx,vue,svelte,cts,mts,json}',

@acao acao Jun 20, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@B2o5T it would need to be tested manually, vscode uses it's own library for glob expansion

@acao acao Jun 20, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@B2o5T same re: these unusual seeming extensions - however, they were requested by users earlier this year and last, and there were lots of emoji reacts 🤷🏻‍♀️ anecdotal experience isn't always enough to evaluate userland haha

there really is no reason not to be exhaustive and inclusive here, since it doesn't hurt anything

@ghost

ghost commented Jun 20, 2023

Copy link
Copy Markdown
Author

@simowe awesome work! have you tested this with both URL schema and file schema?

also, please add a changeset summarizing the work as per the bot comment

lastly, there is one failing test, if you can try to fix it locally

Thanks for the feedback! I've fixed the failing test and added the changeset.

This PR will only reload the schema when the local schema file itself is changed, no other events trigger a reload. Therefore a URL schema will be unaffected by this.

I'm not sure how to best handle a URL schema. Possibly polling on a set interval or reloading the schema whenever any file changes?

@acao

acao commented Jun 20, 2023

Copy link
Copy Markdown
Contributor

@simowe this is the tricky part about URL schemas - we have to (hope) assume the introspection request is configured with cache headers, or just make a fresh request every time we need the schema. More intricate polling mechanisms would be nice but there are no standards for this, just many userland implementations

@acao

acao commented Jun 20, 2023 •

Copy link
Copy Markdown
Contributor

@simowe I think this is fine for now. we can solve the problem for url schemas later. thank you!

@acao
acao merged commit 5513580 into graphql:main Jun 20, 2023
This was referenced Jun 20, 2023
@ghost
ghost deleted the fix/invalidate-schema-on-change branch June 21, 2023 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants