5.2.0 • Published 4 months ago

graphql-language-service v5.2.0

Weekly downloads
36,874
License
MIT
Repository
github
Last release
4 months ago

GraphQL Language Service

NPM npm downloads Snyk Vulnerabilities for npm package License

We welcome your feedback and suggestions.

GraphQL Language Service provides an interface for building GraphQL language services for IDEs.

Partial support for Microsoft's Language Server Protocol is in place, with more to come in the future.

Supported features include:

  • Diagnostics (GraphQL syntax linting/validations) (spec-compliant)
  • Autocomplete suggestions (spec-compliant)
  • Hyperlink to fragment definitions and named types (type, input, enum) definitions (spec-compliant)
  • Outline view support for queries

Installation and Usage

Dependencies

An LSP compatible client with it's own file watcher, that sends watch notifications to the server.

DROPPED: GraphQL Language Service no longer depends on Watchman

Installation

git clone git@github.com:graphql/graphql-language-service.git
cd {path/to/your/repo}
npm install ../graphql-language-service

After pulling the latest changes from this repo, be sure to run yarn run build to transform the src/ directory and generate the dist/ directory.

The library includes a node executable file which you can find in ./node_modules/.bin/graphql.js after installation.

GraphQL configuration file (.graphqlconfig)

Check out graphql-config

The graphql features we support are:

  • customDirectives - ['@myExampleDirective']
  • customValidationRules - returns rules array with parameter ValidationContext from graphql/validation;

Using the command-line interface

The node executable contains several commands: server and a command-line language service methods (lint, autocomplete, outline).

Improving this list is a work-in-progress.

GraphQL Language Service Command-Line Interface.
Usage: bin/graphql.js <command> <file>
    [-h | --help]
    [-c | --configDir] {configDir}
    [-t | --text] {textBuffer}
    [-f | --file] {filePath}
    [-s | --schema] {schemaPath}


Options:
  -h, --help        Show help                                          [boolean]
  -t, --text        Text buffer to perform GraphQL diagnostics on.
                    Will defer to --file option if omitted.
                    Overrides the --file option, if any.
                                                                        [string]
  -f, --file        File path to perform GraphQL diagnostics on.
                    Will be ignored if --text option is supplied.
                                                                        [string]
  --row             A row number from the cursor location for GraphQL
                    autocomplete suggestions.
                    If omitted, the last row number will be used.
                                                                        [number]
  --column          A column number from the cursor location for GraphQL
                    autocomplete suggestions.
                    If omitted, the last column number will be used.
                                                                        [number]
  -c, --configDir   Path to the .graphqlrc configuration file.
                    Walks up the directory tree from the provided config
                    directory, or the current working directory, until a
                    .graphqlrc is found or the root directory is found.
                                                                        [string]
  -s, --schemaPath  a path to schema DSL file
                                                                        [string]

At least one command is required.
Commands: "server, validate, autocomplete, outline"

Architectural Overview

GraphQL Language Service currently communicates via Stream transport with the IDE server. GraphQL server will receive/send RPC messages to perform language service features, while caching the necessary GraphQL artifacts such as fragment definitions, GraphQL schemas etc. More about the server interface and RPC message format below.

The IDE server should launch a separate GraphQL server with its own child process for each .graphqlconfig file the IDE finds (using the nearest ancestor directory relative to the file currently being edited):

./application

  ./productA
    .graphqlconfig
    ProductAQuery.graphql
    ProductASchema.graphql

  ./productB
    .graphqlconfig
    ProductBQuery.graphql
    ProductBSchema.graphql

A separate GraphQL server should be instantiated for ProductA and ProductB, each with its own .graphqlconfig file, as illustrated in the directory structure above.

The IDE server should manage the lifecycle of the GraphQL server. Ideally, the IDE server should spawn a child process for each of the GraphQL Language Service processes necessary, and gracefully exit the processes as the IDE closes. In case of errors or a sudden halt the GraphQL Language Service will close as the stream from the IDE closes.

Server Interface

GraphQL Language Server uses JSON-RPC to communicate with the IDE servers. Microsoft's language server currently supports two communication transports: Stream (stdio) and IPC. For IPC transport, the reference guide to be used for development is the language server protocol documentation.

For each transport, there is a slight difference in JSON message format, especially in how the methods to be invoked are defined - below are the currently supported methods for each transport (will be updated as progress is made):

StreamIPC
DiagnosticsgetDiagnosticstextDocument/publishDiagnostics
AutocompletiongetAutocompleteSuggestionstextDocument/completion
OutlinegetOutlineNot supported yet
Go-to definitiongetDefinitionNot supported yet
File EventsNot supported yetdidOpen/didClose/didSave/didChange events
5.2.0

8 months ago

5.1.7

11 months ago

5.1.7-alpha.0

11 months ago

5.1.6

12 months ago

5.1.5

12 months ago

5.1.4

1 year ago

5.1.3

1 year ago

5.1.2

1 year ago

5.1.1

1 year ago

5.1.0

2 years ago

5.0.6

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.3

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

3.2.5

2 years ago

4.0.0

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.1.5

2 years ago

4.1.0

2 years ago

4.1.2

2 years ago

4.1.1

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.4

2 years ago

3.2.3

2 years ago

3.1.6

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.6

3 years ago

3.0.5

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

4 years ago

3.0.2-alpha.3

4 years ago

3.0.2-alpha.2

4 years ago

3.0.2-alpha.1

4 years ago

3.0.2-alpha.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-alpha.4

4 years ago

3.0.0-alpha.2

4 years ago

3.0.0-alpha.1

4 years ago

2.4.0-alpha.6

4 years ago

2.4.0-alpha.7

4 years ago

2.4.0-alpha.5

4 years ago

2.4.0-alpha.4

4 years ago

2.4.0-alpha.3

4 years ago

2.4.0-alpha.0

4 years ago

2.4.0-alpha.1

4 years ago

2.3.4

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.1

4 years ago

2.3.0

5 years ago

2.1.0

5 years ago

2.0.0

6 years ago

1.3.2

6 years ago

1.2.2

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.18

6 years ago

1.0.16

6 years ago

1.0.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.5-0

7 years ago

0.1.4-0

7 years ago

0.1.3-0

7 years ago

0.1.2-0

7 years ago

0.1.1-0

7 years ago

0.1.0-0

7 years ago

0.0.42

7 years ago

0.0.41

7 years ago

0.0.40

7 years ago

0.0.39

7 years ago

0.0.38

7 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago