
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@gqlite/gql2sql
Advanced tools
A powerful TypeScript library that converts GraphQL queries to optimized SQLite SQL with automatic schema generation, relationship handling, and advanced filtering capabilities.
✅ GraphQL to SQL Conversion - Convert GraphQL queries to optimized SQLite SQL
✅ Automatic Schema Generation - Generate GraphQL schema from existing SQLite databases
✅ Relationship Handling - Support for one-to-many, many-to-one relationships
✅ Deep Nesting Support - Handle complex nested queries with unlimited depth
✅ WHERE Operators - Advanced filtering with >, <, >=, <=, like, != operators
✅ SQL Injection Protection - Prepared statements with parameter binding
✅ N+1 Problem Prevention - Optimized JOIN queries to avoid N+1 issues
✅ JSON Response Format - Clean JSON output using SQLite's JSON functions
import { Database } from "bun:sqlite";
import { graphqlToSqlite } from "./src/gq2sql";
import { createSchemaFromDatabase } from "./src/schema-generator";
const db = new Database("database.sqlite");
const schema = await createSchemaFromDatabase(db);
const query = `
query {
users(where: { name: { like: "%John%" } }) {
id
name
posts(where: { views: { gt: 100 } }) {
id
title
views
}
}
}
`;
const result = await graphqlToSqlite(query, schema, db);
console.log(JSON.stringify(result, null, 2));
Support for advanced filtering with multiple comparison operators:
| Operator | SQL | Description | Example |
|---|---|---|---|
eq | = | Equal | { id: { eq: 1 } } |
ne | != | Not equal | { status: { ne: "deleted" } } |
gt | > | Greater than | { views: { gt: 100 } } |
gte | >= | Greater or equal | { price: { gte: 50.0 } } |
lt | < | Less than | { age: { lt: 30 } } |
lte | <= | Less or equal | { rating: { lte: 4.5 } } |
like | LIKE | Pattern matching | { name: { like: "%John%" } } |
# Multiple conditions (AND)
query {
products(where: {
price: { gte: 10, lte: 100 },
category: { ne: "discontinued" },
name: { like: "%phone%" }
}) {
id
name
price
}
}
# Filtering with relationships
query {
categories(where: { name: { like: "%Tech%" } }) {
id
name
posts(where: { views: { gt: 500 } }) {
id
title
views
user {
name
}
}
}
}
Automatically generate GraphQL schema from existing SQLite databases:
import { createSchemaFromDatabase } from "./src/schema-generator";
const dbConnection = {
async all(sql: string): Promise<any[]> {
return db.query(sql).all();
},
};
const schema = await createSchemaFromDatabase(dbConnection);
The schema generator automatically detects:
Handle complex nested relationships with unlimited depth:
query {
categories {
id
name
posts {
id
title
user {
id
name
posts {
id
title
category {
id
name
}
}
}
}
}
}
The library generates optimized SQL with proper JOINs:
-- GraphQL: users { id, name, posts { title } }
SELECT
t0.id AS id,
t0.name AS name,
json_group_array(
CASE WHEN t1.id IS NOT NULL
THEN json_object('title', t1.title)
ELSE NULL END
) AS posts
FROM users AS t0
LEFT JOIN posts AS t1 ON t0.id = t1.user_id
GROUP BY t0.id;
All queries use prepared statements with parameter binding:
// Safe parameterized query
WHERE t0.name LIKE ? AND t0.views > ?
// Parameters: ["%John%", "100"]
Column names are sanitized to prevent injection:
private sanitizeFieldName(fieldName: string): string {
return fieldName.replace(/[^a-zA-Z0-9_]/g, '');
}
Prevents N+1 queries by generating optimal JOINs:
# Single optimized query instead of N+1
users {
id
posts {
id
category {
name
}
}
}
For optimal performance, create indexes on commonly filtered fields:
CREATE INDEX idx_posts_user_id ON posts(user_id);
CREATE INDEX idx_posts_views ON posts(views);
CREATE INDEX idx_users_name ON users(name);
# Using Bun
bun add graphql
# Using npm
npm install graphql
const query = `
query {
users {
id
name
email
}
}
`;
const query = `
query {
posts(where: { views: { gt: 100 } }) {
id
title
views
}
}
`;
const query = `
query {
users {
id
name
posts {
id
title
category {
name
}
}
}
}
`;
const query = `
query {
users(limit: 10, offset: 20) {
id
name
}
}
`;
graphqlToSqlite(query, schema, database)Main function to convert and execute GraphQL queries.
Parameters:
query (string): GraphQL query stringschema (Schema): Generated schema objectdatabase (Database): SQLite database instanceReturns: Promise<any[]> - Query results as JSON
createSchemaFromDatabase(dbConnection)Generate schema from existing SQLite database.
Parameters:
dbConnection (object): Database connection with all() methodReturns: Promise - Generated schema object
Run the test suite:
# Basic functionality
bun examples/gqlite.ts
# WHERE operators
bun test-where-operators.ts
# Advanced filtering
bun test-advanced-where.ts
# Relationship filtering
bun test-where-relations.ts
The library provides comprehensive error handling:
try {
const result = await graphqlToSqlite(query, schema, db);
console.log(result);
} catch (error) {
console.error('GraphQL conversion error:', error.message);
}
Common error scenarios:
🔄 In Progress:
in, notIn, isNull)📋 Planned:
FAQs
GraphQL => SQL (SQLite)
The npm package @gqlite/gql2sql receives a total of 3 weekly downloads. As such, @gqlite/gql2sql popularity was classified as not popular.
We found that @gqlite/gql2sql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.