apollo-tooling icon indicating copy to clipboard operation
apollo-tooling copied to clipboard

Reload languageServer on `localSchemaFile` change.

Open nodkz opened this issue 6 years ago • 3 comments

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.

nodkz avatar Nov 27 '19 18:11 nodkz

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.

karibertils avatar Mar 04 '20 18:03 karibertils

@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",

andreialecu avatar Apr 21 '20 08:04 andreialecu

@karibertils and @andreialecu a bit late to the party, but you can also use a hook in graphql-codegen:

import { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  schema: 'http://localhost:4000/graphql',
  documents: ['src/**/*.tsx'],
  generates: {
    './src/gql/': {
      preset: 'client'
    }
  },
  hooks: {
    afterAllFileWrite: ['touch apollo.config.js']
  }
}
 
export default config

Source: https://the-guild.dev/graphql/codegen/docs/config-reference/lifecycle-hooks

freakimkaefig avatar Apr 03 '25 09:04 freakimkaefig