Fix broken JS/Java/Rust code samples in quickstart docs
Merged
SH
1d ago+37+37+01234567890123456789-23-23-01234567890123456789
Summary
Fixes several code samples in the quickstart docs that would fail to compile/run as written, found while reviewing getting-started/index.mdx against the actual client APIs (falkordb-ts, jfalkordb, falkordb-rs).
getting-started/index.mdx
- JavaScript:
graph.query()/graph.roQuery()resolve to{ headers, data, ... }, not an iterable.for (const record of result)throwsresult is not iterableat runtime. Now iteratesresult.data. - Java:
Recordhas noget(...)method — onlygetValue(String key)/getValue(int index). Fixedrecord.get("Friend")→record.getValue("Friend")(andPostContent). - Rust:
- Raw string literals (
r#"..."#) had\"escapes around property values, which raw strings don't process — the literal backslashes would break the Cypher text sent to the server. Removed the unneeded escaping. - The query blocks called
.execute().await?while the client was built with the synchronousFalkorClientBuilder::new()(notnew_async()), which isn't awaitable. Switched to the sync API consistently (.execute().expect(...), no.await). record["Friend"]indexing on aRowdoesn't exist;Rowonly exposes.get(column)/.try_get::<T>(column). Fixed to unwrap the per-rowFalkorResultand callrow.try_get::<String>("Friend").
- Raw string literals (
index.mdx (homepage)
- Rust: this snippet uses the async client (
FalkorClientBuilder::new_async()), sonodes.datais aRowStreamimplementingfutures::Stream, not a synchronousIterator.for node in nodes.data.by_ref()doesn't compile against aStream. Replaced withwhile let Some(row) = nodes.data.next().await { ... }underfutures::StreamExt, and unwraps each row'sFalkorResultbefore printing.- Also changed
graph.delete().await?tolet _ = graph.delete().await;so the first run (graph doesn't exist yet) doesn't abort the script, matching the idiom used in falkordb-rs's own examples.
- Also changed
Verification
Checked each fix against the authoritative client sources/docs: falkordb-ts README/npm package examples, jfalkordb's Record.java/Graph.java interfaces, and falkordb-rs's Row/RowStream/QueryBuilder API docs.
Co-Authored-By: Warp agent@warp.dev
Summary by cubic
Fixes code samples in the quickstart docs so they compile and run as written against the actual client APIs.
Bug Fixes
- JavaScript samples iterate
result.datasince query results come back as an object, not an iterable. - Java samples use
Record.getValue(...)instead of the non-existentRecord.get(...). - Rust samples drop escaped quotes inside raw string literals, use the synchronous client consistently in
getting-started, and read columns withrow.try_get(...)instead of indexing. - The homepage Rust sample drains the async
RowStreamwithnext().awaitand ignores the delete error on first run so the script doesn't abort. - Adds
getValueto the spellcheck wordlist, which CI flagged in the new Java comments.
Summary by CodeRabbit
- Documentation
- Updated the getting-started examples to reflect current Rust, JavaScript, and Java patterns for creating graphs and querying results.
- Rust examples demonstrate synchronous operations in the getting-started guide and asynchronous query-result processing in the main guide. The main guide’s deletion example no longer propagates graph-deletion errors.
- JavaScript examples show how to iterate through returned rows, and Java examples clarify how to access record values.