Giter Club home page Giter Club logo

vim-graphql's Introduction

GraphQL for Vim

This Vim plugin provides GraphQL file detection, syntax highlighting, and indentation. It currently targets the June 2018 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
    }
  }
|}];

ReScript Support

GraphQL syntax support inside of ReScript strings is available.

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

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.

vim-graphql's People

Contributors

jparise avatar jfrolich avatar cpitt avatar pjio avatar alem0lars avatar amiralies avatar bbc2 avatar dwalsh01 avatar serixscorpio avatar michaelaquilina avatar mborst avatar tessro avatar timfeirg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.