Inspired by rest.nvim
This plugin uses curl to send the requests. You need to have curl installed in your system.
It uses treesitter to identify the queries. You need treesitter installed in your neovim instance and the graphql parser.
:TSInstall graphqluse 'ulisses-cruz/gql.nvim'use {
'ulisses-cruz/gql.nvim',
config = function()
require 'gql'.setup {
filetypes = { 'graphql' },
keymaps = {
run = '<leader>rr'
}
}
end
}There are only to configuration options for now:
- filetypes: A list of file types the plugin shoul attach to. Defaults to
{ 'graphql' }. - keymaps: A table of action/keymap pairs. Currently there's only the
runaction. It has no default keymap.
- Go to a
graphqlfile where you have your queries; - Put the cursor on the query you what to run (not the query metadata);
- press the keymap you set in your configuration;
You should be prompt to enter the endpoint the query should be sent to. After entering the endpoint a split window should open to show the query response.
If you don't want to enter the endpoint every time, add it as a metadata to the query.
You can do that by adding # endpoint: <your-endpoint> above the query.
# endpoint: https://countries.trevorblades.com/
{
countries {
code
name
}
}You can also configure a default endpoint for all queries in the file, by adding the metadata as the first line of the file. The metadata added above each query has precedence.
# endpoint: https://countries.trevorblades.com/
{
countries {
code
name
}
}
query Country($code: ID!) {
country(code: $code) {
code
name
}
}If your query requires any variable, you can set them as metadata also:
# variables: {
# "code": "CV"
# }
query Country($code: ID!) {
country(code: $code) {
code
name
}
}