Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apollographql/graphql-language-service-parser

Package Overview
Dependencies
Maintainers
7
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollographql/graphql-language-service-parser

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

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created

What is @apollographql/graphql-language-service-parser?

@apollographql/graphql-language-service-parser is a parser for GraphQL language services. It provides tools to parse GraphQL queries, mutations, and subscriptions, making it easier to build GraphQL language services, linters, and other tools that need to understand GraphQL syntax.

What are @apollographql/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 transformation.

const { parse } = require('@apollographql/graphql-language-service-parser');
const query = `
  query GetUser($id: ID!) {
    user(id: $id) {
      name
      email
    }
  }
`;
const ast = parse(query);
console.log(JSON.stringify(ast, null, 2));

Handling Syntax Errors

This feature demonstrates how to handle syntax errors when parsing a GraphQL query. If the query is invalid, an error will be thrown, which can be caught and handled appropriately.

const { parse } = require('@apollographql/graphql-language-service-parser');
const invalidQuery = `
  query GetUser($id: ID!) {
    user(id: $id) {
      name
      email
    }
`;
try {
  const ast = parse(invalidQuery);
} catch (error) {
  console.error('Syntax Error:', error.message);
}

Parsing GraphQL Fragments

This feature allows you to parse GraphQL fragments, which can be reused in multiple queries or mutations. The parsed AST can be used to understand the structure of the fragment.

const { parse } = require('@apollographql/graphql-language-service-parser');
const fragment = `
  fragment UserFields on User {
    name
    email
  }
`;
const ast = parse(fragment);
console.log(JSON.stringify(ast, null, 2));

Other packages similar to @apollographql/graphql-language-service-parser

Keywords

FAQs

Package last updated on 04 Nov 2018

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