apollographql / apollo-tooling

✏️ Apollo CLI for client tooling (Mostly replaced by Rover)
https://apollographql.com
MIT License
3.04k stars 468 forks source link

Reload languageServer on `localSchemaFile` change. #1685

Open nodkz opened 4 years ago

nodkz commented 4 years ago

For now, I'm using monorepo with server and client. And when my watch scripts regenerate schema file I need to manually reload Apollo: Reload Schema (apollographql/reloadService).

It will be nice if vs-code plugin reloads automatically with new localSchemaFile data.

Need to extend somehow the following code: https://github.com/apollographql/apollo-tooling/blob/master/packages/apollo-language-server/src/server.ts#L133

But for now I found a workaround

You need to install File Watcher extension and add the following config to : .vscode/settings.json:

{
  "filewatcher.commands": [
    {
      "match": "\\.graphql*",
      "isAsync": true,
      "cmd": "touch ${workspaceRoot}/apps/client/apollo.config.js",
      "event": "onFileChange"
    }
  ]
}

touch command will refresh apollo.config.js and Apollo for VSCode will catch these changes and reload the schema file.

karibertils commented 4 years ago

I have tried this workaround but it seems the File Watcher extension only picks up changes that are done inside vscode. For example if i touch or modify the schema file in vim it will not run.

I am using https://graphql-code-generator.com/ to generate the schema.graphql file so i am still looking for a solution for this.

andreialecu commented 4 years ago

@karibertils I also use graphql-code-generator, my solution was to add a script to package.json such as:

    "gql:codegen": "graphql-codegen --config codegen.yml && touch apollo.config.js",