
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@apollographql/graphql-language-service-parser
Advanced tools
An online parser for GraphQL for use in syntax-highlighters and code intelligence tools
@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.
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));
The 'graphql' package is the reference implementation of GraphQL for JavaScript. It includes a parser, schema utilities, and execution engine. While it provides similar parsing capabilities, it is more comprehensive and includes tools for executing GraphQL queries and building schemas.
The 'graphql-tools' package provides a set of utilities for building and manipulating GraphQL schemas. It includes schema stitching, mocking, and other advanced features. While it does not focus solely on parsing, it offers a broader set of tools for working with GraphQL.
The 'graphql-tag' package is used to parse GraphQL query strings into ASTs. It is commonly used in client-side applications to define GraphQL queries. While it offers similar parsing capabilities, it is more lightweight and focused on client-side usage.
An online immutable parser for GraphQL, designed to be used as part of syntax-highlighting and code intelligence tools such as for the GraphQL Language Service and codemirror-graphql.
FAQs
An online parser for GraphQL for use in syntax-highlighters and code intelligence tools
The npm package @apollographql/graphql-language-service-parser receives a total of 219,656 weekly downloads. As such, @apollographql/graphql-language-service-parser popularity was classified as popular.
We found that @apollographql/graphql-language-service-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.