agentleFS
doscodosco/graphjin/AGENTS.md

graphjin

AGENTS.md3.2k starsChanged 3 months agoApache-2.0View on GitHub

This document is a guide for AI agents working on the GraphJin codebase. It outlines the architectural patterns, coding conventions, and common tasks associated with maintaining and extending this library. GraphJin is a compiler that turns GraphQL into database queries. For SQL databases, it generates SQL. For MongoDB, it generates a JSON DSL that is translated to aggregation pipelines. It is NOT a typical ORM or resolver-based GraphQL server. When adding new features to GraphJin (operators, syntax, capabilities), remember to…

  • Reads credentials

Trending

Less talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 45 mentionsSep 2026: 2 mentionsOct 2026: 1 mentionNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the dosco/graphjin repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about dosco/graphjin

The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 52

Talked about on GitHub and Hacker News (52 times).

On GitHub · 48

43 more on GitHub
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository2 other files it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

32 rules. About 0 are common, 12 are distinctive, and 20 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 20

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Tests: Add a test case in core/internal/psql/tests.

    line 47
  2. Distinctive:

    Dialect Compatibility: If the feature syntax varies by database (Postgres vs MySQL):

    line 48
  3. Very specific:

    Add a method to the Dialect interface in core/internal/dialect.

    line 49
  4. Very specific:

    DO NOT: use if dialect == ... checks in the shared psql logic.

    line 52
  5. Very specific:

    When adding new features to GraphJin (operators, syntax, capabilities), remember to update the MCP syntax documentation:

    line 56
  6. Very specific:

    When adding a new sources[].capabilities key, add it first to the central registry in core/sourcecap.

    line 67
  7. Very specific:

    If you need to change how GraphJin discovers tables or relationships:

    line 76
  8. Very specific:

    Use standard Go error wrapping (fmt.Errorf("%w", err)).

    line 81
  9. Distinctive:

    Pre-computation: Do heavy lifting (schema analysis, allow-list preparation) at initialization time, not request time.

    line 87
  10. Very specific:

    YAML Config: Use dev.yml for development, prod.yml for production, and agentic.yml for agentic deployments.

    line 90
  11. Very specific:

    Single Integration Test: Use the -run flag with the test function name.

    line 105
  12. Distinctive:

    Package Level Unit Tests: Run tests for a specific package (e.g., SQL generation).

    line 109
  13. Very specific:

    Regression/Feature Tests: Add a new Example_ function in tests/query_test.go or a new file in tests/.

    line 115
  14. Very specific:

    Database Changes: If your test requires new schema elements, update tests/postgres.sql.

    line 116
  15. Very specific:

    Output Verification: Use the // Output: comment at the end of your example function.

    line 117
  16. Very specific:

    Security-critical components: Use Go's built-in fuzz testing (go test -fuzz=FuzzName) for parsers and input validation.

    line 120
  17. Distinctive:

    Every suite function carries a header comment naming what it proves:

    line 143
  18. Very specific:

    Unique names: every created resource uses a smoke_ prefix plus a $(date +%s)_$$ suffix.

    line 158
  19. Very specific:

    Critical: When modifying shared code (e.g., query.go, columns.go), you MUST verify that existing dialects (Postgres, MySQL, SQLite) are not …

    line 199
  20. Distinctive:

    Regression Testing: Always run the full test suite or relevant dialect-specific tests before committing changes to shared logic.

    line 200
  21. Very specific:

    Isolation: If a new feature or dialect requires different behavior, prefer using if dialect == ...

    line 201
  22. Distinctive:

    When adding support for a new database (e.g., Oracle, SQL Server), follow these guidelines to ensure consistency and correctness.

    line 205
  23. Very specific:

    Do NOT add implicit ordering: Never add automatic ORDER BY to queries that don't specify one, even if it would make behavior "match" …

    line 211
  24. Distinctive:

    When tests fail on a new database due to different row ordering:

    line 217
  25. Very specific:

    Fix the test, not the database layer: Add explicit order_by: { id: asc } (or appropriate column) to the GraphQL query.

    line 219
  26. Distinctive:

    When implementing a new dialect, handle these common differences:

    line 232
  27. Distinctive:

    When a feature genuinely isn't supported by a database:

    line 256
  28. Distinctive:

    Combine related skips: If multiple databases share the same limitation, combine them:

    line 266
  29. Distinctive:

    Prefer fixing over skipping: Only skip when the feature truly cannot be supported.

    line 274
  30. Distinctive:

    Always run all dialect tests: before merging changes to shared code.

    line 289
  31. Very specific:

    Relationship Lookups: Use $lookup with pipelines for field selection and filtering:

    line 350
  32. Very specific:

    Mutations with Allowlist: Use raw_document with parameter placeholder for runtime substitution, not compile-time embedding.

    line 369

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

GraphJin Agent Guide

This document is a guide for AI agents working on the GraphJin codebase. It outlines the architectural patterns, coding conventions, and common tasks associated with maintaining and extending this library.

Architectural Overview

GraphJin is a compiler that turns GraphQL into database queries. For SQL databases, it generates SQL. For MongoDB, it generates a JSON DSL that is translated to aggregation pipelines. It is NOT a typical ORM or resolver-based GraphQL server.

  • Core Philosophy: Push as much work as possible to the database.
  • No Resolvers: Data fetching is done via a single generated SQL query. Do not add resolvers for database fields.
  • Schema Driven: The database schema (sdata) is the source of truth.

Directory Structure & Responsibilities

PathComponentResponsibility
core/api.goPublic APIThe only entry point for users. Changes here are breaking.
core/core.goEngineInternal orchestration, initialization, and state management.
core/internal/sdataSchemaMetadata about tables, columns, and relationships. Graph traversal logic.
core/internal/qcodeIR CompilerFront-end compiler. Parses GraphQL -> QCode (Intermediate Representation).
core/internal/psqlSQL CompilerBack-end compiler. QCode -> SQL. Handles dialect differences.
core/internal/dialectDialect InterfaceDatabase-specific SQL generation methods. Each dialect implements this interface.
core/internal/graphGraphQL ParserLexer and parser for GraphQL input. Builds AST.
core/internal/jsnJSON ProcessingHigh-performance JSON parsing and filtering utilities.
serv/HTTP ServiceStandalone server with REST, GraphQL, and WebSocket APIs.
auth/AuthenticationAuth providers: JWT, Auth0, Firebase, Rails session.
cmd/CLI ToolCommand-line interface for migrations, deployment, and management.
conf/ConfigurationYAML-based config loading and validation.
wasm/WebAssemblyWASM build for NodeJS integration.
mongodriver/MongoDB DriverCustom database/sql-compatible driver for MongoDB. Translates JSON DSL to aggregation pipelines.

Build Commands

make build    # Build for current platform
make test     # Run tests (requires Docker for database containers)
make lint     # Lint code
make gen      # Generate code (stringer, etc.)

Coding Guidelines

1. Adding New SQL Features

To add support for a new SQL feature (e.g., a new aggregation or function):

  1. Update qcode: meaningful changes often start here. Ensure the new feature can be represented in the QCode struct (core/internal/qcode/qcode.go).
  2. Update psql: Implement the SQL generation logic in core/internal/psql/query.go (or mutate.go for writes).
  3. Tests: Add a test case in core/internal/psql/tests. These tests compare the generated SQL against an expected string.
  4. Dialect Compatibility: If the feature syntax varies by database (Postgres vs MySQL):
    • Add a method to the Dialect interface in core/internal/dialect.
    • Implement it in postgres.go and mysql.go.
    • Return an error from the implementation if the feature is not supported by that dialect.
    • DO NOT use if dialect == ... checks in the shared psql logic.

2. MCP Maintenance

When adding new features to GraphJin (operators, syntax, capabilities), remember to update the MCP syntax documentation:

  • File: serv/mcp_syntax.go
  • What to update:
    • FilterOperators struct - add new filter operators
    • querySyntaxReference - add operator lists and syntax descriptions
    • queryExamples - add example queries demonstrating new features
  • Why: AI assistants using MCP call get_query_syntax to learn available operators. Undocumented operators won't be used by AI agents.

3. Source Capability Maintenance

When adding a new sources[].capabilities key, add it first to the central registry in core/sourcecap. Do not introduce ad hoc capability strings in catalog, security, MCP, or source-default code.

GraphJin-owned system and workflow capabilities are not source capabilities. Add those to core/featurecap and enforce them through the centralized system-root policy.

  • What the registry owns: canonical source kinds, capability keys, mode defaults, action, severity, enforcement type, read-only behavior, summaries, recommendations, and examples.
  • What subsystems own: actual runtime enforcement hooks for their surface (for example CodeSQL, filesystem read-only, control-plane tables, or MCP tools).
  • Tests: registry, catalog, security, config validation, and permission tests must pass. If a capability is not runtime-enforced yet, mark it as config_audit.

4. Modifying Schema Discovery

If you need to change how GraphJin discovers tables or relationships:

  • Focus on core/internal/sdata/schema.go and tables.go.
  • Modifications here affect the graph used for query planning.

5. Error Handling

  • Use standard Go error wrapping (fmt.Errorf("%w", err)).
  • Fail fast during initialization (NewGraphJin).
  • During query execution, return meaningful error messages that help the user debug their GraphQL query.

6. Performance

  • Zero Allocation: Strive for zero-allocation in the hot path (GraphQL execution).
  • Pre-computation: Do heavy lifting (schema analysis, allow-list preparation) at initialization time, not request time.

7. Configuration

  • YAML Config: Use dev.yml for development, prod.yml for production, and agentic.yml for agentic deployments; GO_ENV=agentic requires agentic.yml, and agentic configs can use inherits: prod to reuse production settings.
  • Production Mode: In production, all queries must be pre-saved (no dynamic client queries). This is a security feature.
  • Environment Variables: Secrets and connection strings should come from environment variables, not config files.

Testing Guidelines

1. Running Tests

  • Requirement: Docker must be running.
  • Command: make test
  • Note: This command runs integration tests that require a real database connection.
  • Mechanism: The tests will automatically spin up a Postgres container.
  • Time: First run may take a moment to pull images; subsequent runs are faster but still involve container startup overhead.

2. Running Specific Tests

To avoid running the entire suite (which can be slow):

  • Single Integration Test: Use the -run flag with the test function name.
    go test -v -run Example_queryWithJsonColumn ./tests
  • Package Level Unit Tests: Run tests for a specific package (e.g., SQL generation).
    go test -v ./core/internal/psql

3. Adding New Tests

  • Regression/Feature Tests: Add a new Example_ function in tests/query_test.go or a new file in tests/.
  • Database Changes: If your test requires new schema elements, update tests/postgres.sql.
  • Output Verification: Use the // Output: comment at the end of your example function. The test runner checks stdout against this comment.

4. Fuzz Testing

  • Security-critical components: Use Go's built-in fuzz testing (go test -fuzz=FuzzName) for parsers and input validation.
  • Focus areas: GraphQL lexer/parser, JSON processing, SQL generation edge cases.

Demo Smoke Suites (examples/*/scripts/smoke.sh)

Each vertical demo (coffee-roastery, saas-ops, pcb-fab, corrugated-plant, …) ships a black-box smoke suite that runs against a live demo server. These are contract checks over HTTP/MCP, not Go tests — start the server first:

graphjin serve --demo --path examples/coffee-roastery
examples/coffee-roastery/scripts/smoke.sh              # base checks
examples/coffee-roastery/scripts/smoke.sh --agent-eval # + open-ended agent evals

Flags: --agent (require agent checks), --agent-eval (stricter model-driven evals), --no-agent, --deep (waits for real background sweeps), --model-resolution, --url URL.

1. Where code goes

  • Domain checks (this demo's tables, saved queries, workflows) go in the demo's own scripts/smoke.sh.
  • Reusable capability suites (run_watch_lifecycle_suite, run_refusal_suite, …) go in examples/lib/smoke-common.sh and are parameterized by table/prompt so every demo can call them.
  • The shared lib provides: graphql <label> <query>, mcp_tool <name> <json-args>, post_json, run_agent_rest_prompt, assert_jq <file> <jq-expr> <message>, assert_jq_args, log/pass/fail, and identity helpers (graphql_as_identity, build_auth_args_for_identity) that send dev headers plus a minted HS256 JWT so the same test runs against header-trust and JWT-verified servers.

2. Capability contract comments

Every suite function carries a header comment naming what it proves:

# Capability: TASK-VERIFY-NOW
# Contract: Closing with a passing saved-query proof closes the task ...
# Deeper coverage: TestTaskImmediateVerificationPassAndFail.
run_task_control_plane_suite() { ... }

scripts/check-capability-smokes.sh enforces that these IDs exist and map to suites — add the ID there when introducing a new capability. Deeper coverage: names the Go tests that own the fine-grained cases; the smoke proves the wiring end to end.

3. State hygiene (non-negotiable)

Smoke suites run against a persistent, reused demo state (<path>/demo). Anything you leak is still there months later, and catalog pollution directly degrades the agent: one leaked-state instance carried 108 smoke_route_* subscription entries against 3 real saved queries, which broke agent discovery outright.

  • Unique names: every created resource uses a smoke_ prefix plus a $(date +%s)_$$ suffix.
  • Track and clean: append created IDs to suite-level arrays and delete them in smoke_extra_cleanup (invoked by the shared EXIT trap). Cleanup must be idempotent — suffix every delete with || true.
  • Known leak: inserting a gj_watch registers its named subscription as a gj_artifacts row with kind: "saved_query" that currently outlives the watch. Until watch deletion cascades, cleanup must also delete that artifact by name.
  • Owner scoping: gj_artifacts, gj_watch, and gj_task rows are owner-scoped — delete them under the same identity that created them; an admin bulk-delete will silently skip other owners' rows.
  • Reset: interrupted runs leak by design. To reset a demo completely, stop the server and delete <path>/demo; a fresh provision also clears the <path>/.graphjin control-plane store (artifacts, watches, tasks) — on older builds delete that directory yourself, or stale saved queries survive the reset.

4. Agent evals (--agent-eval)

  • Assert outcomes, not tool presence. "The agent called query_catalog" is procedure; the eval must check the conclusion: real seeded values quoted in the answer, a verdict actually stated, and negative patterns excluding the known failure shapes (schema-blaming, "cannot determine", invented columns). Pin an exact verdict or figure only when one is unambiguously derivable from the seed — if the prompt's scope is genuinely open (orders alone vs orders plus subscriptions), several verdicts are defensible and pinning one makes the eval reject correct answers. Route the calculation through a workflow before pinning its result.
  • Natural language first. At least one eval per demo uses the PROMPTS.md wording verbatim with zero tool coaching — that is what users type, and tool-prescriptive prompts hide real failures.
  • Absorb variance, not wrongness. Model-driven evals may retry (2 attempts); an assertion that a wrong conclusion could pass on retry is a broken eval.
  • Model floor: these evals need roughly a gpt-4.1-class server model (GJ_AGENT_MODEL=gpt-4.1); provider defaults in the mini/flash tier stall in the discovery loop. Switch providers per run with GJ_AGENT_PROVIDER / GJ_AGENT_API_KEY_ENV.

5. Data-accuracy eval loop (scripts/agent-data-eval.sh)

The smoke --agent-eval suites are wiring checks; the data-accuracy loop is the scored harness for improving the agent's answers. It boots the saas-ops demo with GJ_DEFAULT_LIMIT=10 (so truncated-page aggregation is reproducible), runs agent/testdata/data_eval_cases.json through agent/cmd/skill-eval, and scores every case on three dimensions:

  1. Ground truth — the answer must match a runtime oracle: a trusted DB-side-aggregate GraphQL query executed against the same server's /api/v1/graphql, so date-relative seeds and data_anchor shifting never desync ground truth.
  2. Method — the executed queries (read from the response action trail) must show the database computed the result (sum_*/count_*/order_by on aggregates). This catches right-number-wrong-method runs that sum a row page client-side on a table small enough to get away with it. The principle under test: the model plans, the engine computes.
  3. Efficiency — advisory per-case budgets on actor turns and tokens; exceeding one feeds the runaway failure bucket, never a hard gate.

Failed runs are auto-classified (client_side_aggregation, stale_anchor, wrong_window, ranking_method, truncated_finalize, runaway, …) so a report reads as a diagnosis. Per-case verdicts are majority-of-repeats with a separate consistency score, so single-sample flake is absorbed without hiding real wrongness.

The loop:

make agent-data-eval-baseline                      # before a change
# ...land the prompt/guardrail change...
make agent-data-eval BASELINE=.graphjin-evals/<report>.json   # exits 2 on gate failure
make agent-data-eval-trend                         # recall history across iterations

The candidate phase gates as a ratchet: ground-truth recall and method recall must not regress vs the baseline (method is the leading indicator — it can improve before answers do). The 0.90 ground-truth target is a warning until reached, so below-target candidates that improve still land during the climb. --weak-arm gpt-4.1-mini adds an advisory flash-tier run to measure guardrail robustness; it never gates.

Authoring rules for new cases (enforced by agent/data_eval_corpus_test.go): prompts are natural language with zero tool coaching; oracles are pure aggregates or limit: 1 group-bys only (pure aggregate roots self-set no-limit, keeping oracles immune to the low boot limit); tolerance stays within 1–5% and only for genuinely fractional values; ranking cases must require order_by in their method rule. When a field report arrives (an external eval, a user complaint), convert each failure into a corpus case in the matching group — that is how feedback accumulates instead of evaporating.

Key constraints

  • Do not use ORMs internally.
  • Do not use reflection in the hot path.
  • Keep core/api.go stable.

4. Shared Code Stability

  • Critical: When modifying shared code (e.g., query.go, columns.go), you MUST verify that existing dialects (Postgres, MySQL, SQLite) are not broken.
  • Regression Testing: Always run the full test suite or relevant dialect-specific tests before committing changes to shared logic.
  • Isolation: If a new feature or dialect requires different behavior, prefer using if dialect == ... blocks or interface methods over changing the common logic that other dialects rely on.

Adding New Database Dialects

When adding support for a new database (e.g., Oracle, SQL Server), follow these guidelines to ensure consistency and correctness.

1. SQL Standards & Undefined Behavior

Result ordering is undefined without ORDER BY in all SQL databases.

  • Do NOT add implicit ordering: Never add automatic ORDER BY to queries that don't specify one, even if it would make behavior "match" another database.
  • Why: Adding implicit ordering causes performance overhead (unnecessary sorts), violates SQL standards, and creates unexpected behavior for users.
  • PostgreSQL's "consistent" ordering is a myth: Tests that pass on PostgreSQL without explicit ordering are relying on undefined implementation behavior, not guaranteed semantics. These tests are buggy.

2. Test Determinism

When tests fail on a new database due to different row ordering:

  • Fix the test, not the database layer: Add explicit order_by: { id: asc } (or appropriate column) to the GraphQL query.
  • Tests must be deterministic: Any test that checks specific result ordering must specify that ordering explicitly.
  • Pattern for ordering fix:
    // BAD - relies on undefined ordering
    gql := `query { products(limit: 2) { id name } }`
    
    // GOOD - explicit ordering
    gql := `query { products(limit: 2, order_by: { id: asc }) { id name } }`

3. Dialect Implementation Checklist

When implementing a new dialect, handle these common differences:

FeaturePostgreSQLMySQLSQLiteOracleMSSQLMongoDB
Row limitingLIMIT nLIMIT nLIMIT nFETCH FIRST n ROWS ONLYFETCH NEXT n ROWS ONLY$limit stage
OffsetOFFSET nOFFSET nOFFSET nOFFSET n ROWSOFFSET n ROWS$skip stage
Boolean typeNative booleanTINYINT(1)INTEGERNUMBER(1) - needs JSON conversionBIT (0/1)Native boolean
Recursive CTEWITH RECURSIVEWITH RECURSIVEWITH RECURSIVEWITH (no RECURSIVE keyword)WITH (no RECURSIVE keyword)$graphLookup
JSON aggregationjson_agg()JSON_ARRAYAGG()json_group_array()JSON_ARRAYAGG()STRING_AGG() + FOR JSON PATHNative (documents)
Identifier quoting"name"`name`"name""NAME" (case-sensitive)[name]N/A (JSON keys)
RelationshipsSQL JOINSQL JOINSQL JOINSQL JOINSQL JOIN$lookup stage

4. Function Return Type Handling

Some databases don't have native types that map cleanly to JSON:

  • Oracle booleans: Oracle functions return NUMBER (0/1), not boolean. Configure function return types in the GraphJin config:
    conf.Functions = []core.Function{{Name: "is_active", ReturnType: "boolean"}}
  • The SQL compiler will wrap these with appropriate CASE/FORMAT JSON logic.

5. Feature Skip Patterns

When a feature genuinely isn't supported by a database:

  • Skip with clear documentation:
    // Skip for Oracle: recursive CTE identifier handling not yet supported
    if dbType == "oracle" {
        fmt.Println(`{"expected":"output"}`)
        return
    }
  • Combine related skips: If multiple databases share the same limitation, combine them:
    // Skip for MySQL/SQLite: PostgreSQL array column syntax not supported
    if dbType == "mysql" || dbType == "sqlite" {
        fmt.Println(`{"expected":"output"}`)
        return
    }
  • Prefer fixing over skipping: Only skip when the feature truly cannot be supported. If it's just a syntax difference, implement it in the dialect.

6. Running Dialect-Specific Tests

Each dialect has its own test script:

./scripts/test-postgres.sh  # PostgreSQL tests
./scripts/test-mysql.sh     # MySQL tests
./scripts/test-sqlite.sh    # SQLite tests
./scripts/test-oracle.sh    # Oracle tests
./scripts/test-mssql.sh     # MSSQL tests
./scripts/test-mongo.sh     # MongoDB tests

Always run all dialect tests before merging changes to shared code.

7. Subscription Cursor Prefix (Common Pitfall)

Cursor prefixes must use ctx.GetSecPrefix() (the dynamic timestamp-based prefix like gj-65a8b3c0:). Hardcoding "gj-" will cause subscriptions to hang because firstCursorValue() in core/crypt.go won't recognize the cursor. Always test with Example_subscriptionWithCursor.

MongoDB Implementation

MongoDB is fundamentally different from SQL databases. Instead of generating SQL, GraphJin generates a JSON DSL that the custom MongoDB driver (mongodriver/) translates into aggregation pipelines.

Architecture Differences

AspectSQL DatabasesMongoDB
Query outputSQL stringJSON DSL structure
RelationshipsJOIN clauses$lookup pipeline stages
FilteringWHERE clause$match pipeline stage
OrderingORDER BY$sort pipeline stage
Field selectionSELECT columns$project pipeline stage
MutationsINSERT/UPDATE/DELETEinsertOne/updateOne/deleteOne

Key Files for MongoDB

FilePurpose
core/internal/dialect/mongodb.goMain dialect implementation. Generates JSON DSL from QCode.
mongodriver/driver.godatabase/sql-compatible driver registration and connection handling.
mongodriver/conn.goConnection implementation that executes JSON DSL against MongoDB.
mongodriver/pipeline.goTranslates JSON DSL to MongoDB aggregation pipeline and handles result transformation.
mongodriver/query.goParses JSON DSL and handles parameter substitution.

JSON DSL Format

The MongoDB dialect generates JSON structures like:

{
  "operation": "aggregate",
  "collection": "users",
  "field_name": "users",
  "pipeline": [
    {"$match": {"_id": 1}},
    {"$project": {"_id": 0, "id": "$_id", "email": 1, "full_name": 1}}
  ]
}

For mutations:

{
  "operation": "insertOne",
  "collection": "users",
  "raw_document": "$1",
  "return_pipeline": [...]
}

MongoDB-Specific Considerations

  1. ID Translation: GraphQL uses id, MongoDB uses _id. The dialect and driver handle this translation.
  2. Relationship Lookups: Use $lookup with pipelines for field selection and filtering:
    {"$lookup": {
      "from": "products",
      "let": {"userId": "$_id"},
      "pipeline": [{"$match": {"$expr": {"$eq": ["$owner_id", "$$userId"]}}}],
      "as": "products"
    }}
  3. Array Columns: For array-based relationships (e.g., category_ids: [1,2,3]), use $in instead of $eq:
    {"$match": {"$expr": {"$in": ["$_id", "$$categoryIds"]}}}
  4. JSON Virtual Tables (RelEmbedded): For embedded JSON arrays queried as virtual tables, use $unwind + $lookup + $group pattern instead of simple $lookup.
  5. Parameter Substitution: Parameters are placeholders ($1, $2) in the JSON DSL. The driver's SubstituteParams() resolves them at runtime.
  6. Mutations with Allowlist: Use raw_document with parameter placeholder for runtime substitution, not compile-time embedding. This ensures cached queries work correctly with different request data.

MongoDB Feature Support Status

FeatureStatusNotes
Basic queries✅ SupportedField selection, filtering, ordering, limits
Relationships✅ SupportedVia $lookup with pipeline
Array column joins✅ SupportedUses $in for matching
JSON virtual tables✅ SupportedUses $unwind/$lookup/$group pattern
Mutations (insert/update/delete)✅ SupportedWith raw_document for allowlist mode
Subscriptions✅ SupportedUses polling (change streams possible future enhancement)
Aggregation functions❌ Not yetcount, sum, avg, etc.
iregex❌ DifferentMongoDB uses $regex, needs mapping
Custom functions❌ Not yetDatabase functions not supported

Testing MongoDB Changes

# Run all MongoDB tests
./scripts/test-mongo.sh

# Run specific test
./scripts/test-mongo.sh -run "TestQueryWithJsonColumn"

Important: MongoDB tests require Docker. The test script starts a MongoDB container automatically.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.