js-graphql-language-service
js-graphql-language-service copied to clipboard
A Node.js powered language service that provides a GraphQL language API on top of codemirror-graphql and graphql-js.

JS GraphQL Language Service
This repo is no longer maintained. It was made obsolete by the release of js-graphql-intellij-plugin 2.0
A Node.js powered language service that provides a GraphQL language API on top of codemirror-graphql and graphql-js.
It provided various GraphQL language features in js-graphql-intellij-plugin 1.x for IntelliJ IDEA and WebStorm, but was replaced with a Java-based native implementaton in 2.0.
Features:
- Schema-aware completion and error highlighting
- Syntax highlighting
- Configurable GraphQL schema retrieval and reloading based on a local file or a url using 'then-request'
- Schema documentation for types and tokens
Inspired by TypeScript's language service, this project makes it possible to leverage Facebook's JavaScript implementation of GraphQL inside IDEs such as IntelliJ IDEA and WebStorm -- without re-implementing GraphQL in Java.
Running
npm run-script start starts the language service at http://127.0.0.1:3000/js-graphql-language-service
Using the Language Service API
The API is based on POSTing JSON commands. The following commands are supported:
setProjectDir: Set the project directory from which agraphql.config.jsoncan be loaded to determine how the Schema can be retrieved from a file or urlgetSchema: Gets the GraphQL schema that has been loaded using thesetProjectDircommand, falling back to a bare-bones default schemagetTokens: Gets the tokens contained in a buffer. Relay.QL and gql templating is supported unless env is passed as{"env":"graphql"}getAnnotations: Gets the errors contained in a buffer, optionally with support for Relay.QL templates using{"env":"relay"}getHints: Gets the schema-aware completions for a buffer at a specifiedlineancch, optionally with support for Relay.QL templates using{"env":"relay"}getAST: Gets the GraphQL AST of a buffer, optionally with support for Relay.QL templates using{env:"relay"}getTokenDocumentation: Gets the schema documentation for a token in a buffer at a specifiedlineandch, optionally with support for Relay.QL templates using{"env":"relay"}getTypeDocumentation: Gets schema documentation for a specific GraphQL Type based on the description, fields, implementations, and interfaces specified in the current schema
Supported environments using the env parameter:
graphql: For GraphQL file buffers. No templating is processed, and all error annotations are returned.graphql-template: For use withgraphqltagged templates that contain placeholders, e.g. for variables. Annotations are filtered to allow placeholder use cases.relay: For use withRelay.QLtagged Relay templates, e.g. as injections in a JavaScript and TypeScript buffer. Annotations are filtered to allow Relay use cases.apollo: For use withgqltagged Apollo Client templates, e.g. as injections in a JavaScript and TypeScript buffer. Annotations are filtered to allow Apollo use cases.lokka: For use withgqltagged Lokka Client templates, e.g. as injections in a JavaScript and TypeScript buffer. Annotations are filtered to allow Lokka use cases.
Please see src/tests/spec.js for examples of how to use the language service, and src/tests/data for the response data.
Building
Make sure browserify is installed globally with:
npm install -g browserify
To bundle the bin\server.js file into a single dist/js-graphql-language-service.dist.js file for distribution:
npm run-script bundle-to-dist
Or, the dist file can be outputted directly into a js-graphql-intellij-plugin checkout using:
npm run-script bundle-to-intellij-plugin
License
MIT