Socket
Socket
Sign inDemoInstall

graphql-language-service-parser

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-language-service-parser

An online parser for GraphQL for use in syntax-highlighters and code intelligence tools


Version published
Weekly downloads
158K
increased by34.22%
Maintainers
4
Weekly downloads
 
Created

What is graphql-language-service-parser?

The graphql-language-service-parser npm package provides tools for parsing GraphQL queries and schemas. It is useful for building GraphQL language services, such as syntax highlighting, auto-completion, and error checking in IDEs.

What are graphql-language-service-parser's main functionalities?

Parsing GraphQL Queries

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 manipulation.

const { parse } = require('graphql-language-service-parser');
const query = `{
  user(id: "1") {
    name
    age
  }
}`;
const ast = parse(query);
console.log(JSON.stringify(ast, null, 2));

Handling Syntax Errors

This feature helps in identifying and handling syntax errors in GraphQL queries. The parser throws an error if the query is not syntactically correct, which can be caught and handled appropriately.

const { parse } = require('graphql-language-service-parser');
const query = `{
  user(id: "1") {
    name
    age
  }
`;
try {
  const ast = parse(query);
} catch (error) {
  console.error('Syntax Error:', error.message);
}

Locating Nodes in AST

This feature allows you to locate specific nodes in the AST based on a character offset. It is useful for features like syntax highlighting and error reporting in IDEs.

const { parse, getLocation } = require('graphql-language-service-parser');
const query = `{
  user(id: "1") {
    name
    age
  }
}`;
const ast = parse(query);
const location = getLocation(query, 10);
console.log(location);

Other packages similar to graphql-language-service-parser

Keywords

FAQs

Package last updated on 26 May 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc