Getting Started with JSON Schema x GraphQL
Welcome! This guide will help you get up and running with the JSON Schema x GraphQL project, whether you’re using it in your own projects or contributing to the codebase.
Table of Contents
- Quick Start (5 minutes)
- Understanding the Project
- Setting Up for Development
- Your First Contribution
- Common Tasks
- Troubleshooting
- Next Steps
Quick Start (5 minutes)
For Users
If you just want to use the converter:
# Install via npm
npm install json-schema-x-graphql
# Or via yarn
yarn add json-schema-x-graphqlBasic usage:
import { convertSdlToJson, convertJsonToSdl } from "json-schema-x-graphql";
// Convert GraphQL SDL to JSON Schema
const jsonSchema = await convertSdlToJson(`
type User @key(fields: "id") {
id: ID!
name: String!
}
`);
// Convert JSON Schema back to SDL
const sdl = await convertJsonToSdl(jsonSchema);
console.log(sdl);For Contributors
If you want to contribute to the project:
# Clone the repository
git clone https://github.com/json-schema-x-graphql/json-schema-x-graphql.git
cd json-schema-x-graphql
# Install dependencies
cargo build
npm install
# Run tests
cargo test
npm testUnderstanding the Project
What Problem Does This Solve?
Organizations often need to:
- Validate data before it enters their systems (JSON Schema)
- Expose that data via GraphQL APIs (GraphQL SDL)
- Maintain a single source of truth for both
This project enables exactly that using x-graphql-* extensions.
Key Concepts
1. Three Namespaces
The project uses three distinct naming conventions:
{
"user_id": "123", // snake_case (database/JSON Schema)
"x-graphql-field-name": "userId", // camelCase (GraphQL API)
"x-graphql-federation-requires": "email" // hyphen-case (metadata)
}2. Minimal Extensions
Only 15 core fields are required for lossless conversion:
- 4 always required (type-name, type-kind, field-name, field-type)
- 3 when applicable (field-non-null, list-item-non-null, argument-default-value)
- 6 for federation (keys, requires, provides, external, shareable, override-from)
- 2 optional arrays (directives, arguments)
3. Lossless Round-Tripping
SDL → JSON Schema → SDLNo information is lost. All directives, arguments, and metadata are preserved.
Architecture Overview
┌─────────────────────┐
│ JSON Schema │
│ (Validation) │
│ │
│ snake_case fields │
│ + x-graphql-* │
└──────────┬──────────┘
│
│ Rust WASM Converter
▼
┌─────────────────────┐
│ GraphQL SDL │
│ (API) │
│ │
│ camelCase fields │
│ + directives │
└─────────────────────┘Setting Up for Development
Prerequisites
Make sure you have these installed:
Step 1: Clone and Install
# Clone the repository
git clone https://github.com/json-schema-x-graphql/json-schema-x-graphql.git
cd json-schema-x-graphql
# Install Rust dependencies
cargo build
# Install Node.js dependencies
npm installStep 2: Verify Installation
# Run Rust tests
cargo test
# Run JavaScript tests (when available)
npm test
# Check formatting
cargo fmt --check
npm run lintStep 3: Build WASM Module
# Build the WASM module
npm run build:wasm
# This creates pkg/ directory with:
# - graphql_json_schema_wasm_bg.wasm
# - graphql_json_schema_wasm.js
# - graphql_json_schema_wasm.d.tsStep 4: Run the Frontend (when available)
cd frontend
npm install
npm run devOpen http://localhost:5173 to see the live editor.
Your First Contribution
Option 1: Fix a Typo or Improve Docs
The intake_processest way to contribute!
- Find a typo or unclear section
- Click “Edit” on GitHub or clone the repo
- Make your change
- Submit a PR
Files to check:
- index
- /docs/concepts/json-schema-graphql-gaps
- /docs/contributing
- examples/*.schema.json
Option 2: Add a Test Case
Help us improve coverage!
- Look at
src/lib.rs(ortests/directory when created) - Find a function without tests
- Write a test case
- Submit a PR
Example:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_enum_with_deprecated_values() {
let sdl = r#"
enum Status {
ACTIVE
DISABLED @deprecated(reason: "Use ARCHIVED")
ARCHIVED
}
"#;
let json_schema = sdl_to_json(sdl).unwrap();
let status_def = &json_schema.definitions["Status"];
assert_eq!(status_def.x_graphql_type_kind, GraphQLKind::Enum);
let configs = status_def.x_graphql_enum_value_configs.unwrap();
assert!(configs["DISABLED"].deprecated.unwrap());
}
}Option 3: Implement a Feature
Ready for more?
- Check Good First Issues
- Comment on the issue to claim it
- Create a branch:
git checkout -b feature/your-feature - Implement the feature
- Add tests
- Submit a PR
Common Tasks
Task 1: Validate a JSON Schema
# Using a JSON Schema validator like AJV
npm install -g ajv-cli
# Validate your schema against the meta-schema
ajv validate \
-s schema/x-graphql-extensions.schema.json \
-d examples/user-service.schema.jsonTask 2: Add a New Example
- Create a new file in
examples/ - Follow the structure of
user-service.schema.json - Include:
- At least one entity type with
@key - Federation directives
- Field arguments
- Enum types
- At least one entity type with
- Validate it against the meta-schema
- Add documentation in the file’s description
Task 3: Test Round-Trip Conversion
// In your test file
#[test]
fn test_round_trip() {
let original_sdl = r#"
type Product @key(fields: "id") {
id: ID!
name: String!
price: Float
}
"#;
// SDL → JSON
let json_schema = sdl_to_json(original_sdl).unwrap();
// JSON → SDL
let regenerated_sdl = json_to_sdl(&json_schema).unwrap();
// Parse both and compare ASTs
let original_ast = parse_sdl(original_sdl);
let regenerated_ast = parse_sdl(®enerated_sdl);
assert_eq!(original_ast, regenerated_ast);
}Task 4: Profile WASM Performance
# Build with profiling
cargo build --release --features wasm
# Use browser DevTools Performance tab
# Or use criterion for benchmarking
cargo benchTask 5: Update Meta-Schema
If you need to add a new x-graphql-* extension:
- Add the pattern to
schema/x-graphql-extensions.schema.json - Add validation rules (type, pattern, etc.)
- Update
examples/user-service.schema.jsonto demonstrate usage - Update
/docs/reference/sdl-linterwith documentation - Add tests for the new extension
Troubleshooting
Problem: Rust compilation fails
Solution:
# Update Rust
rustup update
# Clean and rebuild
cargo clean
cargo buildProblem: WASM build fails
Solution:
# Reinstall wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Try building again
wasm-pack build --target web --releaseProblem: Tests fail
Solution:
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_name -- --nocapture
# Check for formatting issues
cargo fmt
cargo clippyProblem: JSON Schema validation fails
Solution:
- Check that
$schemapoints tohttps://json-schema.org/draft/2020-12/schema - Ensure all
x-graphql-*keys usehyphen-case - Verify GraphQL type names use
PascalCase - Verify GraphQL field names use
camelCase - Check that patterns match (e.g., federation URLs)
Problem: Round-trip conversion loses data
Solution:
- Check if you’re using a required extension field
- Verify directive arguments are preserved
- Ensure enum value configs are included
- Check if field arguments have default values
Next Steps
Learn More
- Read the specs: /docs/reference/sdl-linter
- Study examples: Look at files in
examples/ - Explore architecture: Read /docs/concepts/json-schema-graphql-gaps
- API reference: /docs/api
Join the Community
- GitHub Discussions: Ask questions, share ideas
- Discord: Real-time chat (link in README)
- Office Hours: Friday 3-4pm UTC on Discord
Suggested Learning Path
- Week 1: Read documentation, understand concepts
- Week 2: Fix typos, improve docs, validate examples
- Week 3: Add test cases, explore codebase
- Week 4: Implement small features
- Week 5+: Tackle larger features, review PRs
Resources
Quick Reference
Key Files
schema/x-graphql-extensions.schema.json- Meta-schema definitionexamples/user-service.schema.json- Comprehensive examplesrc/lib.rs- Core converter logicCargo.toml- Rust project configpackage.json- npm package config
Key Commands
# Development
cargo build # Build Rust project
cargo test # Run Rust tests
cargo fmt # Format Rust code
cargo clippy # Lint Rust code
npm install # Install Node dependencies
npm test # Run JavaScript tests
npm run build # Build everything
npm run build:wasm # Build WASM module
# Git workflow
git checkout -b feature/name # Create feature branch
git add . # Stage changes
git commit -m "message" # Commit changes
git push origin feature/name # Push to GitHubGetting Help
- 📖 Read: /docs/contributing
- 💬 Ask: GitHub Discussions
- 🐛 Report: GitHub Issues
- 👥 Chat: Discord server (link in README)
Welcome to the project! We’re excited to have you here. 🎉
If you have any questions, don’t hesitate to ask in Discussions or reach out to the maintainers.
Happy coding! 🚀