Giter VIP home page Giter VIP logo

vscode-graphql's Introduction

VSCode GraphQL

๐Ÿ’กNote: This extension no longer supports .prisma files. If you are using this extension with Prisma 1, please rename your datamodel from datamodel.prisma to datamodel.graphql and this extension would pick that up.

GraphQL extension VSCode built with the aim to tightly integrate the GraphQL Ecosystem with VSCode for an awesome developer experience.

Features

General features

  • Load the extension on detecting graphql-config file at root level or in a parent level directory
  • Load the extension in .graphql, .gql files
  • Load the extension on detecting gql tag in js, ts, jsx, tsx, vue files
  • Support graphql-config files with one project and multiple projects

.graphql, .gql file extension support

  • syntax highlighting (type, query, mutation, interface, union, enum, scalar, fragments)
  • autocomplete suggestions
  • validation against schema
  • snippets (interface, type, input, enum, union)
  • hover support
  • go to definition support (input, enum, type)

gql tagged template literal support

  • syntax highlighting (type, query, mutation, interface, union, enum, scalar, fragments)
  • autocomplete suggestions
  • validation against schema
  • snippets

Usage

  1. Install watchman.
  2. Install the VSCode GraphQL Extension.

This extension requires a valid .graphqlconfig or .graphqlconfig.yml file in the project root. You can read more about that here.

To support language features like "go-to definition" across multiple files, please include includes key in the graphql-config per project. For example,

projects:
  app:
    schemaPath: src/schema.graphql
    includes: ["**/*.graphql"]
    extensions:
      endpoints:
        default: http://localhost:4000
  db:
    schemaPath: src/generated/db.graphql
    includes: ["**/*.graphql"]
    extensions:
      codegen:
      - generator: graphql-binding
        language: typescript
        output:
          binding: src/generated/db.ts

Notice that includes key supports glob pattern and hence ["**/*.graphql"] is also valid.

If you want to use a workspace version of TypeScript however, you must manually install the plugin along side the version of TypeScript in your workspace:

npm install --save-dev @divyenduz/ts-graphql-plugin

Then add a plugins section to your tsconfig.json or jsconfig.json

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "@divyenduz/ts-graphql-plugin"
      }
    ]
  }
}

Finally, run the Select TypeScript version command in VS Code to switch to use the workspace version of TypeScript for VS Code's JavaScript and TypeScript language support. You can find more information about managing typescript versions in the VS Code documentation.

Development

This plugin uses two language services based on the context.

  1. GraphQL language service when in .graphql, .gql files
  2. Augmentation of GraphQL language service in TypeScript language service when using gql tag in .ts/.js/.tsx/.jsx files based on this documentation.

Setup and logging for development are different for these language services as documented below.

A. Testing/logging GraphQL Language Features

  1. Clone the repository - https://github.com/prismagraphql/vscode-graphql
  2. npm install
  3. Open it in VSCode
  4. Go to the debugging section and run the launch program "Extension"
  5. This will open another VSCode instance with extension enabled
  6. Open a project with a graphql config file - ":electric_plug: graphql" in VSCode status bar indicates that the extension is in use
  7. Logs for GraphQL language service will appear in output section under GraphQL Language Service GraphQL Language Service Logging

B. Testing/logging TypeScript GraphQL Plugin Features

  1. Clone ts-graphql-plugin and go to its directory.
  2. npm install and npm link
  3. Use npm link @divyenduz/ts-graphql-plugin in the folder that you have opened to test things in extension host - this is required for development
  4. Switch to use workspace typescript - this is required for development
  5. To see the logs of TypeScript language service, instructions are documented here. We need to set TSS_LOG environment variable to log to a file (see below) and then open VSCode through command line for it to pick up the TSS_LOG exported variable and then we can tail the file.
export TSS_LOG="-logToFile true -file <absolute-path> -level verbose"
cd <graphql-project-path>
code .
tail -f <absolute-path> | grep ts-graphql-plugin-log

License

MIT

vscode-graphql's People

Contributors

borekb avatar cmckni3 avatar deadcoder0904 avatar dependabot[bot] avatar ganemone avatar intellix avatar marktani avatar n1arash avatar orta avatar peterholak avatar schickling avatar thakkaryash94 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.