🚀 Transform your SOQL queries into GraphQL with zero learning curve
Are you a Salesforce developer struggling with GraphQL syntax? Already an SOQL ninja 🥷🏿? This library is your bridge between the familiar SOQL world and the powerful GraphQL ecosystem.
Perfect for:
- Salesforce developers migrating to GraphQL
- Teams building modern APIs with Salesforce data
- Developers who want to leverage GraphQL without learning new syntax
- Projects requiring type-safe, efficient data queries
- 🔄 Seamless Conversion: Convert any SOQL query to GraphQL instantly
- 🎯 Type Safety: Full TypeScript support with comprehensive type
- 🧪 Battle Tested: Comprehensive test suite with 104+ test cases
- 🔧 Developer Friendly: Excellent error messages and debugging support
- 📚 Well Documented: Extensive documentation and examples
- ⚡ Real-time: Supports dynamic queries with variable binding
npm install @sf-explorer/soql-to-graphqlyarn add @sf-explorer/soql-to-graphqlpnpm add @sf-explorer/soql-to-graphql<script src="https://unpkg.com/@sf-explorer/soql-to-graphql@latest/dist/index.js"></script>- Node.js 18.x or higher
- TypeScript 5.x (optional, for type definitions)
import soql2graphql from '@sf-explorer/soql-to-graphql';
// Simple SOQL query
const soql = 'SELECT Id, Name FROM Account LIMIT 5';
const graphql = soql2graphql(soql);
console.log(graphql);Output:
query {
uiapi {
query {
Account(first: 5) {
edges {
node {
Id
Name {
value
}
}
}
}
}
}
}const soql = `
SELECT Id, Name, Owner.Name,
(SELECT Id, Name, Amount FROM Opportunities WHERE StageName = 'Closed Won')
FROM Account
WHERE Industry = 'Technology'
ORDER BY Name ASC
LIMIT 10
`;
const graphql = soql2graphql(soql);Output:
query {
uiapi {
query {
Account(
first: 10
where: { Industry: { eq: "Technology" } }
orderBy: { Name: { order: ASC } }
) {
edges {
node {
Id
Name {
value
}
Owner {
Name {
value
}
}
Opportunities(where: { StageName: { eq: "Closed Won" } }) {
edges {
node {
Id
Name {
value
}
Amount {
value
}
}
}
}
}
}
}
}
}
}const soql = `
SELECT Id, Name, Email
FROM Contact
WHERE AccountId = :accountId
AND IsActive = :isActive
ORDER BY Name ASC
`;
const variables = {
accountId: 'ID!',
isActive: 'Boolean',
};
const graphql = soql2graphql(soql, variables);Output:
query ($accountId: ID!, $isActive: Boolean) {
uiapi {
query {
Contact(
where: {
and: [
{ AccountId: { eq: $accountId } }
{ IsActive: { eq: $isActive } }
]
}
orderBy: { Name: { order: ASC } }
) {
edges {
node {
Id
Name {
value
}
Email {
value
}
}
}
}
}
}
}const soql = `
SELECT Id, Name, Amount, StageName
FROM Opportunity
WHERE (Amount > 10000 AND StageName = 'Closed Won')
OR (Amount > 5000 AND StageName = 'Prospecting')
ORDER BY Amount DESC
LIMIT 20
`;
const graphql = soql2graphql(soql);Output:
query {
uiapi {
query {
Opportunity(
first: 20
where: {
or: [
{
and: [
{ Amount: { gt: 10000 } }
{ StageName: { eq: "Closed Won" } }
]
}
{
and: [
{ Amount: { gt: 5000 } }
{ StageName: { eq: "Prospecting" } }
]
}
]
}
orderBy: { Amount: { order: DESC } }
) {
edges {
node {
Id
Name {
value
}
Amount {
value
}
StageName {
value
}
}
}
}
}
}
}Converts a SOQL query string to GraphQL format.
soql(string, required): The SOQL query to convertvariables(VariableDefinitions, optional): Variable definitions for bind variables
string: The generated GraphQL query
import soql2graphql, {
VariableDefinitions,
} from '@sf-explorer/soql-to-graphql';
const soql = 'SELECT Id FROM Account WHERE Name = :name';
const variables: VariableDefinitions = { name: 'String' };
const graphql = soql2graphql(soql, variables);interface VariableDefinitions {
[prop: string]: string;
}
type ComparisonOperator =
| 'eq'
| 'ne'
| 'like'
| 'in'
| 'gt'
| 'gte'
| 'lt'
| 'lte';
type LogicalOperator = 'and' | 'or';
type OrderDirection = 'ASC' | 'DESC';| Feature | Status | Example |
|---|---|---|
| Basic SELECT | ✅ | SELECT Id, Name FROM Account |
| WHERE clauses | ✅ | WHERE Name = 'Test' |
| ORDER BY | ✅ | ORDER BY Name ASC |
| LIMIT | ✅ | LIMIT 10 |
| Relationships | ✅ | SELECT Owner.Name FROM Account |
| Subqueries | ✅ | SELECT Id, (SELECT Id FROM Opportunities) FROM Account |
| Variable binding | ✅ | WHERE Name = :name |
| Logical operators | ✅ | WHERE A = 1 AND B = 2 |
| Comparison operators | ✅ | WHERE Amount > 1000 |
| IN clauses | ✅ | WHERE Id IN ('001', '002') |
| LIKE patterns | ✅ | WHERE Name LIKE '%Test%' |
| Functions | ✅ | SELECT COUNT(Id) FROM Account |
# Optional: Set custom GraphQL endpoint
GRAPHQL_ENDPOINT=https://your-instance.salesforce.com/graphql
# Optional: Enable debug mode
DEBUG=soql-to-graphqltry {
const graphql = soql2graphql(invalidSoql);
} catch (error) {
console.error('Conversion failed:', error.message);
// Handle error appropriately
}// ❌ Incorrect
const soql = 'SELECT Id FROM'; // Missing table name
// ✅ Correct
const soql = 'SELECT Id FROM Account';// ❌ Incorrect
const soql = 'SELECT Id FROM Account WHERE Name = :name';
const variables = { name: 'John' }; // Missing type definition
// ✅ Correct
const soql = 'SELECT Id FROM Account WHERE Name = :name';
const variables = { name: 'String' }; // Include type// ❌ Incorrect - Missing parentheses
const soql = 'SELECT Id FROM Account WHERE A = 1 AND B = 2 OR C = 3';
// ✅ Correct - Proper grouping
const soql = 'SELECT Id FROM Account WHERE (A = 1 AND B = 2) OR C = 3';Enable debug mode to see detailed conversion information:
process.env.DEBUG = 'soql-to-graphql';
const graphql = soql2graphql(soql);- Check the Issues for known problems
- Create a new issue with:
- Your SOQL query
- Expected vs actual output
- Error messages
- Environment details
Q: Can I use this with any GraphQL client? A: Yes! The output is standard GraphQL that works with any client.
Q: Does this support all SOQL features? A: We support the most common SOQL features. Check the supported features table.
Q: How do I handle custom fields?
A: Custom fields work the same as standard fields. Just use the API name: SELECT Custom_Field__c FROM Account.
Q: Can I convert multiple queries at once? A: Currently, you need to convert each query individually, but you can batch the calls for efficiency.
- Node.js 18.x or higher
- npm 8.x or higher
- Git
# Clone the repository
git clone https://github.com/sf-explorer/soql-to-graphql.git
cd soql-to-graphql
# Install dependencies
npm install
# Run the development server
npm run dev
# Run tests in watch mode
npm run test:watch| Script | Description |
|---|---|
npm run build |
Build the project for production |
npm run build:watch |
Build in watch mode for development |
npm run test |
Run the complete test suite |
npm run test:watch |
Run tests in watch mode |
npm run test:ci |
Run tests for CI environment |
npm run lint |
Run ESLint code quality checks |
npm run lint:fix |
Fix ESLint issues automatically |
npm run prettier |
Format code with Prettier |
npm run type-check |
Run TypeScript type checking |
npm run ci |
Run complete CI pipeline locally |
src/
├── types.ts # TypeScript type definitions
├── constants.ts # Application constants
├── operators.ts # SOQL operator conversion logic
├── whereConverter.ts # WHERE clause conversion
├── fieldConverter.ts # Field conversion logic
├── queryConverter.ts # Main query conversion
├── converter.ts # Main entry point
└── main.ts # Public API
__test__/
├── unit/ # Unit tests for individual modules
├── integration/ # End-to-end integration tests
└── fixtures/ # Test data and fixtures
The project includes comprehensive testing with 96%+ coverage:
-
🧪 Unit Tests: Individual module testing
-
🔗 Integration Tests: End-to-end functionality
-
🛡️ Error Handling: Edge cases and error scenarios
-
📊 Coverage Reports: Detailed coverage analysis
- ESLint: Code quality and style enforcement
- Prettier: Consistent code formatting
- TypeScript: Type safety and IntelliSense
- Husky: Git hooks for quality gates
- Jest: Comprehensive testing framework
This project uses Git hooks to ensure code quality:
- Pre-commit: Automatically formats and lints staged files
- Pre-push: Verifies all files are properly formatted before push
See Git Hooks Documentation for detailed information.
We welcome contributions! Here's how to get started:
git clone https://github.com/YOUR_USERNAME/soql-to-graphql.git
cd soql-to-graphqlgit checkout -b feature/your-feature-name- Write clean, well-documented code
- Add tests for new functionality
- Update documentation as needed
- Follow the existing code style
npm run ci # Run complete CI pipeline- Provide a clear description of your changes
- Reference any related issues
- Ensure all CI checks pass
Our GitHub Actions workflow ensures code quality:
- 🔄 Continuous Integration: Runs on every push and PR
- 🔒 Security Audits: Automated vulnerability scanning
- 📦 Dependency Updates: Weekly automated updates
- 🚀 Release Automation: Automated versioning and publishing
- 📊 Coverage Reporting: Code coverage tracking
We use automated releases with GitHub Actions:
- Trigger Release: Use GitHub Actions workflow or create a git tag
- Automated Testing: All tests run automatically
- Version Update: Version number incremented automatically
- NPM Publishing: Package published to NPM automatically
- GitHub Release: Release notes and changelog generated
Quick Release Commands:
# Patch release (bug fixes)
npm run version:patch
# Minor release (new features)
npm run version:minor
# Major release (breaking changes)
npm run version:majorSee Release Guide for detailed instructions.
This project is licensed under the MIT License - a permissive open-source license that allows you to:
- Use commercially - Use in commercial projects and products
- Modify - Change the code to fit your needs
- Distribute - Share the code with others
- Sublicense - Include in your own projects with different licenses
- Private use - Use in private projects without restrictions
- Include the license - Keep the MIT license text in your distribution
- Include copyright - Maintain the copyright notice
- No warranty - The software is provided "as is" without warranty
See the complete LICENSE file for the full legal text.
The MIT License was chosen because it:
- Maximizes adoption - Easy for businesses to use
- Minimal restrictions - Simple and permissive
- Industry standard - Widely recognized and trusted
- Developer friendly - Clear and easy to understand
- 📖 Documentation: Full documentation
- 🐛 Issues: Report bugs
- 💬 Discussions: Community discussions
- 📧 Contact: ndespres@gmail.com
This utility would be nothing without these powerful libraries:
- SOQL Parser JS - SOQL parsing engine
- JSON to GraphQL - GraphQL query generation
If this project helps you, please give it a ⭐ on GitHub!
