Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
graphql-language-service
Advanced tools
An interface for building GraphQL language services for IDEs
The graphql-language-service npm package provides a set of tools and utilities for working with GraphQL language features. It includes functionalities such as parsing, validation, and autocompletion, which are essential for building GraphQL development tools and editors.
Parsing
This feature allows you to parse a GraphQL query string into an Abstract Syntax Tree (AST). The AST can then be used for further analysis or transformation.
const { parse } = require('graphql-language-service-parser');
const query = `query { user(id: 1) { name } }`;
const ast = parse(query);
console.log(JSON.stringify(ast, null, 2));
Validation
This feature allows you to validate a GraphQL query against a schema. It helps in identifying errors and ensuring that the query adheres to the schema's rules.
const { validate } = require('graphql');
const { parse } = require('graphql-language-service-parser');
const { specifiedRules } = require('graphql-language-service');
const schema = /* GraphQLSchema object */;
const query = `query { user(id: 1) { name } }`;
const ast = parse(query);
const errors = validate(schema, ast, specifiedRules);
console.log(errors);
Autocomplete
This feature provides autocompletion suggestions for a given position in a GraphQL query. It is useful for building IDE extensions and other developer tools that enhance the GraphQL development experience.
const { getAutocompleteSuggestions } = require('graphql-language-service-interface');
const schema = /* GraphQLSchema object */;
const query = `query { user(`;
const position = { line: 0, character: 12 };
const suggestions = getAutocompleteSuggestions(schema, query, position);
console.log(suggestions);
The 'graphql' package is the reference implementation of GraphQL for JavaScript. It provides a complete suite of tools for building GraphQL servers and clients, including parsing, validation, and execution. While it offers similar functionalities to 'graphql-language-service', it is more focused on server-side operations and less on language services for development tools.
The 'codemirror-graphql' package provides a set of CodeMirror modes and utilities for working with GraphQL. It includes features like syntax highlighting, linting, and autocompletion. Compared to 'graphql-language-service', it is more focused on integrating GraphQL capabilities into the CodeMirror editor.
Note: This package will soon be renamed to graphql-language-service-cli
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:
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
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.
.graphqlrc.yml
)Check out graphql-config
The graphql features we support are:
customDirectives
- ['@myExampleDirective']
customValidationRules
- returns rules array with parameter ValidationContext
from graphql/validation
;The node executable contains several commands: server
and a command-line language service methods (validate
, 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.yml 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"
FAQs
The official, runtime independent Language Service for GraphQL
The npm package graphql-language-service receives a total of 294,215 weekly downloads. As such, graphql-language-service popularity was classified as popular.
We found that graphql-language-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.