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

[lsp-server] vscode-graphql triggers large amounts of requests to my graphql server for bulk file change events in 0.11.0 #3622

Open
Slessi opened this issue Jun 17, 2024 · 3 comments · May be fixed by #3631
Assignees
Labels
bug lsp-server graphql-language-service-server

Comments

@Slessi
Copy link

Slessi commented Jun 17, 2024

Current Behavior (if applicable)

When I use graphql-codegen to generate types from my schema whilst VSCode is open, vscode-graphql automatically sends tens or hundreds of requests to my backend server to get the introspection schema.

In this video, I have two terminals running. Top terminal is my backend server which prints a log everytime it receives a request. Bottom terminal is me just generating types with graphql-codegen. You will see on 0.11.0 my backend server gets spammed, but on 0.9.3 it does not.

Untitled.mp4

Desired Behavior

A change to my generated types should not cause vscode-graphql to need to re-request introspection information. If it does, it should certainly not need to do it more than once.

My graphql.config.cjs:

module.exports = {
  projects: {
    default: {
      schema: ['http://localhost:8080/graphql'],
      documents: ['src/**/!(*.d).{ts,tsx}', '!src/types/graphql.ts'],
      extensions: {
        codegen: {
          hooks: {
            afterOneFileWrite: ['prettier --write --ignore-path=.prettierignore'],
          },
          config: {
            withHooks: true,
            withHOC: false,
            withComponent: false,
            avoidOptionals: {
              field: true,
              inputValue: false,
              object: true,
              defaultValue: true,
            },
            scalars: {
              Time: {
                input: 'Date | string',
                output: 'string',
              },
            },
          },
          generates: {
            'src/types/graphql.ts': {
              plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo', 'fragment-matcher'],
            },
          },
        },
      },
    },
  },
};
@Slessi Slessi added enhancement lsp-server graphql-language-service-server labels Jun 17, 2024
@acao
Copy link
Member

acao commented Jun 25, 2024

@Slessi looking into this today, the new schema polling should not be behaving like this on watch events. Something is resetting the schema cache for every watched file change, and it should not be

@acao acao added bug and removed enhancement labels Jun 25, 2024
@acao acao self-assigned this Jun 25, 2024
@acao acao linked a pull request Jun 25, 2024 that will close this issue
@acao
Copy link
Member

acao commented Jun 25, 2024

update: I've churned on it some this afternoon and I think the lru-cache invalidation needs more work because of the file watching/mass file change case I hadn't considered. Luckily the new integration tests I've added helped me spot regressions for the cache lifecycle in one approach to this bug that I've tried. If I can't find a solution by mid day tomorrow, maybe sooner, I may just remove the new lru-cache based schema polling cache invalidation logic and patch 0.11.x until I can make sure it's working properly for the mass watched file changes case - which is not just an issue for users of graphql-codegen, but any other codegens for frameworks in other languages, or even codegens which are unrelated. I imagine the same bug happens with a git pull and a huge upstream diff.

I added this feature at the end of preparing this release, and only tested with editor file changes (oof), but it's actually quite small to remove and only one of many improvements 0.11.x offers

@acao acao changed the title [lsp-server] vscode-graphql triggers large amounts of requests to my graphql server in 0.11.0 [lsp-server] vscode-graphql triggers large amounts of requests to my graphql server for bulk file change events in 0.11.0 Jun 25, 2024
@acao
Copy link
Member

acao commented Jun 28, 2024

I have an update! I've identified what might be the true source of the issue, which is MessageProcessor.cacheConfigSchemaFile() - this method is what re-writes the cached SDL file for mixed/network schema config scenarios, and it just needs to be debounced, along with ensuring the debounce-ish effect of the short TTL schema LRU cache, hoping to have a working fix tomorrow as I juggle a few unexpected disruptions this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug lsp-server graphql-language-service-server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants