• Stars
    star
    482
  • Rank 91,212 (Top 2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Vim plugin that provides GraphQL file detection, syntax highlighting, and indentation.

GraphQL for Vim

This Vim plugin provides GraphQL file detection, syntax highlighting, and indentation. It currently targets the October 2021 Edition of the GraphQL specification.

Installation

This plugin requires Vim version 8 or later. Equivalent Neovim versions are also supported.

Using vim-plug

  1. Add Plug 'jparise/vim-graphql' to ~/.vimrc
  2. vim +PluginInstall +qall

Using Vim Packages

mkdir -p ~/.vim/pack/jparise/start
cd ~/.vim/pack/jparise/start
git clone https://github.com/jparise/vim-graphql.git graphql
vim -u NONE -c "helptags graphql/doc" -c q

Syntax Highlighting

Complete syntax highlighting is enable for the graphql filetype. This filetype is automatically selected for filenames ending in .graphql, .graphqls, and .gql.

If you would like to enable automatic syntax support for more file extensions (e.g., *.prisma), create a file named ~/.vim/after/ftdetect/graphql.vim containing autocommand lines like:

au BufNewFile,BufRead *.prisma setfiletype graphql

JavaScript and TypeScript Support

GraphQL syntax support inside of ES2015 template literals is provided. It works "out of the box" with Vim 8.2+'s JavaScript and TypeScript language support. The extended JavaScript syntax provided by the vim-javascript plugin is also supported.

For older versions of Vim, TypeScript support can be enabled by installing the yats plugin.

const query = gql`
  {
    user(id: ${uid}) {
      firstName
      lastName
    }
  }
`;

The list of recognized tag names is defined by the g:graphql_javascript_tags variable, which defaults to ["gql", "graphql", "Relay.QL"].

You can also add a # gql or # graphql comment at the start of a template string to indicate that its contents should be considered GraphQL syntax.

const query = `# gql
  {
    user(id: ${uid}) {
      firstName
      lastName
    }
  }
`;

Syntax highlighting within .jsx / .tsx files is also supported. These filetypes can be "compound" (javascript.jsx and typescript.tsx) or use the "react" variants (javascriptreact and typescriptreact).

Syntax highlighting is also available within Vue templates.

ReasonML Support

GraphQL syntax support inside of ReasonML template strings using graphql-ppx is available.

[%graphql {|
  query UserQuery {
    user {
      id
      name
    }
  }
|}];

The %relay extension point is also supported.

ReScript Support

GraphQL syntax support inside of ReScript strings is available.

%graphql(`
  query UserQuery {
    user {
      id
      name
    }
  }
`)

The %relay extension node is also supported.

PHP Support

GraphQL syntax inside of heredoc and nowdoc strings is supported. The string identifier must be named GQL (case-insensitive).

<?php
$my_query = <<<GQL
{
  user(id: ${uid}) {
    firstName
    lastName
  }
}
GQL;

Language Server Protocol Support

Language Server Protocol (LSP) implementations can enable editor features like schema-aware completion.

Testing

The test suite uses Vader.vim. To run all of the tests from the command line:

make test

License

This code is released under the terms of the MIT license. See LICENSE for details.

More Repositories

1

chrome-utm-stripper

Browser extension that strips Google Analytics (UTM) parameters, and various other click tracking tokens, from URL query strings
JavaScript
702
star
2

stale

Stale identifies (and optionally deletes) stale Delicious and Pinboard links.
Python
149
star
3

python-reloader

Dependency-based Python Module Reloader
Python
136
star
4

php-python

Embedded Python Extension for PHP
C
68
star
5

gmail-fixed-font

Use your browser's monospace font for message body text in Gmail
JavaScript
60
star
6

AFHTTPClientLogger

Configurable HTTP request logger for AFNetworking
Objective-C
41
star
7

apprankings

App Store Rankings Scraper
Python
40
star
8

flake8-assertive

Flake8 unittest assert method checker
Python
31
star
9

vim-phabricator

Vim plugin for Phabricator and Arcanist
Vim Script
18
star
10

vesta

Vestaboard client library for Python
Python
17
star
11

PropertyKit

PropertyKit provides tools for working with Objective-C Declared Properties
Objective-C
12
star
12

dotfiles

My public dotfiles
Vim Script
6
star
13

flask-facebook

Facebook Support for Flask
Python
4
star
14

haitwu-appengine

Haitwu - Find Haikus in Tweets
Python
4
star
15

indelible-ink

Indelible Ink
Python
3
star
16

flake8-author

Flake8 extension that checks Python modules for __author__ attributes
Python
3
star
17

pwdcomposer

Password Composer for iOS
3
star
18

tgprot

The Telegard Protocol Pack
3
star
19

django-ink

Ink is a blogging application for Django.
Python
3
star
20

dammit-winamp

DAMMIT WinAMP plugin that Soco and I wrote at Computer Science House in the fall of 1998
C++
2
star
21

MIDI

MIDI Input Library for Windows
C++
2
star
22

gh-cat

Concatenate and print the contents of files from a remote GitHub repository
Shell
1
star
23

pygame-starfield

PyGame Starfield Example
Python
1
star
24

brightkite-python

Python library for the Brightkite API
Python
1
star
25

jparise.github.com

Indelible.org
HTML
1
star
26

yuri

Yuri is a URI manipulation library for Python
Python
1
star
27

marconi

Marconi is a network media server.
Python
1
star
28

indelible-django

Indelible.org Django Site
Python
1
star
29

evite-gcal

A Greasemonkey script that replaces the Outlook Calendar link in Evite invitations with a Google Calendar link.
JavaScript
1
star
30

caching-dns

Caching DNS Server in Visual Basic
Visual Basic
1
star
31

rugen.org

Rugen.org
1
star