Developing Connectors in Vim and NeoVim
Configure Vim/NeoVim to validate Apollo Connectors
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.
Prerequisites
A current Vim or NeoVim installation
If using NeoVim you must use version >=5.0 to use its native LSP
Otherwise, the
coc.nvim
plugin 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-preview or later
latest
version of Rover won't give you the pre-release
version 0.27.0-preview.0. You need to specify this exact version until 0.27.0
is released.Use the following command to install the correct version:
1curl -sSL https://rover.apollo.dev/nix/v0.27.0-preview.0 | sh
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
graphql
is 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 lsp
command 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.nvim
documentation for more info: