@n1kben/graphql-lsp
v2.0.1
Published
A simple GraphQL Language Server Protocol implementation that works without configuration files
Maintainers
Readme
GraphQL LSP
A simple, zero-configuration GraphQL Language Server Protocol implementation.
Features
- No configuration required - Works immediately without
.graphqlrcor schema files - Go to definition - Jump to type, enum, union, interface, scalar, and input definitions
- Hover documentation - View complete type definitions and documentation on hover
- Document symbols - See all definitions in the outline/symbol list
- Built-in types - Includes documentation for GraphQL's built-in scalar types (String, Int, Float, Boolean, ID)
Installation
NPM
npm install -g @n1kben/graphql-lspFrom source
git clone https://github.com/n1kben/graphql-lsp.git
cd graphql-lsp
npm install
npm linkEditor Setup
Neovim
Create a file at ~/.config/nvim/lsp/graphql.lua:
return {
cmd = { "graphql-lsp", "--stdio" },
filetypes = { "graphql" },
}If you're using a custom LSP setup, you can configure it like this:
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
-- Register the GraphQL LSP
if not configs.graphql then
configs.graphql = {
default_config = {
cmd = { 'graphql-lsp', '--stdio' },
filetypes = { 'graphql' },
root_dir = lspconfig.util.root_pattern('.git', 'package.json'),
single_file_support = true,
},
}
end
lspconfig.graphql.setup{}VS Code
Add to your settings.json:
{
"graphql.lsp": {
"command": "graphql-lsp",
"args": ["--stdio"]
}
}Other Editors
Any editor that supports LSP can use this server. Configure it to run:
graphql-lsp --stdioUsage
Once installed and configured, the LSP will automatically provide:
- Go to Definition - Place cursor on a type name and use your editor's "go to definition" command
- Hover Information - Hover over any type to see its complete definition and documentation
- Document Outline - Use your editor's symbol/outline view to see all GraphQL definitions
Supported GraphQL Definitions
type- Object typesinterface- Interface typesenum- Enumeration typesunion- Union typesscalar- Scalar typesinput- Input object types
Documentation Comments
The LSP recognizes both GraphQL documentation styles:
"""
Multi-line documentation
for types and fields
"""
type User {
id: ID!
}
# Single line comment
enum Role {
ADMIN
USER
}Why This LSP?
Most GraphQL language servers require configuration files (.graphqlrc, graphql.config.js) and schema setup. This LSP is designed for:
- Quick editing of standalone GraphQL files
- Projects where you don't want to set up full GraphQL tooling
- Simple schema exploration and editing
- Working with GraphQL files without a complex project structure
Limitations
- Single file support only (no cross-file references)
- No query/mutation validation against a schema
- No field-level go-to-definition within types
- No autocomplete (yet)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Author
n1kben
