Graph Development in Vim and NeoVim
Configure Vim/NeoVim to give you fast feedback as you type
This guide outlines how to set up the Apollo Language Server in NeoVim using its native Language Server Protocol (LSP) client or in Vim/NeoVim using the coc.nvim plugin.
With this setup, you can get the same validations that composition provides, with errors and hints highlighted in your schema files on each save.
Prerequisites
A current Vim or NeoVim installation
If using NeoVim you must use version >=5.0 to use its native LSP
Otherwise, the
coc.nvimplugin also provides an LSP client and can be used with Vim version >= 9.0.0438 and NeoVim version >= 0.8.
Rover version 0.27.0 or later
Using NeoVim's (<= v10.x) native LSP client
NeoVim's native LSP client makes integrating language servers, including the Apollo Language Server, straightforward. This guide doesn't cover keybindings or UI customization, but the following configuration will set up nvim to work with Apollo Connectors.
Configuration
Add the following snippet to your init.lua or any other Lua configuration file for NeoVim:
1vim.api.nvim_create_autocmd('FileType', {
2 pattern = 'graphql',
3 callback = function(ev)
4 vim.lsp.start({
5 name = 'apollo-language-server',
6
7 -- If you're using a profile, you can append `'--profile', 'default'`
8 -- to this list (substitute `default` for your profile name)
9 cmd = {'rover', 'lsp', '--supergraph-config', 'supergraph.yaml'},
10
11 -- Set the "root directory" to the parent directory of the file in the
12 -- current buffer (`ev.buf`) that contains a `supergraph.yaml` file.
13 root_dir = vim.fs.root(ev.buf, {'supergraph.yaml'}),
14 })
15 end,
16})Notes
The File Type Autocommand configuration triggers whenever a file with the type
graphqlis opened. If you want to be more selective about the types of files you want to use with the Apollo Language Server, modify this logic to suit your preferences.For more information about NeoVim's native LSP client, run the
:help lspcommand innvim.
Using coc.nvim with Vim/NeoVim
If you're using coc.nvim as your LSP client, you can configure it to work with the Apollo Language Server with a few lines of configuration.
Configuration
Add the following to your coc-settings.json file, usually located in ~/.vim/coc-settings.json or ~/.config/nvim/coc-settings.json. Alternatively, run the command :CocConfig in any buffer to open the config file. Add the following:
1{
2 // ...
3 "languageserver": {
4 "apollo-language-server": {
5 "command": "rover",
6
7 // If you're using a profile, you can append `'--profile', 'default'`
8 // to this list (substitute `default` for your profile name)
9 "args": ["lsp", "--supergraph-config", "supergraph.yaml"],
10 "filetypes": ["graphql"],
11
12 // Set the "root directory" to the parent directory of the file in the
13 // current buffer that contains a `supergraph.yaml` file.
14 "rootPatterns": ["supergraph.yaml"]
15 }
16 }
17}Notes
Refer to the
coc.nvimdocumentation for more info: