Skip to content

feat: add Query.relationship helper - #1903

Merged
abnegate merged 5 commits into
mainfrom
feat/query-relationship
Oct 15, 2026
Merged

abnegate merged 5 commits into
mainfrom
feat/query-relationship

Conversation

@abnegate

@abnegate abnegate commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds Query.relationship to generated SDKs so clients can constrain populated related documents.

Query.relationship('comments', [
    Query.equal('approved', true),
    Query.orderDesc('$createdAt'),
    Query.limit(25),
])

This matches Query::relationship() / TYPE_RELATIONSHIP in utopia-php/database#968.

The helper takes a relationship attribute and inner queries (filters, order, select, pagination), then serializes them as nested query objects — the same shape as Query.elemMatch.

Languages

PHP, Web/Node, Deno, React Native, Dart/Flutter, Python, Ruby, Kotlin/Android, .NET/Unity, Swift/Apple, Go, Rust.

Skills docs include the new helper.

Test plan

  • Generated PHP Query::relationship unit test (8 assertions)
  • Generated PHP Pint
  • Generated Go gofmt
  • E2E query-helper expectation added for every language that already tests elemMatch
  • CI on this PR (59/59 green)

Merge order

  • Server support lands first: utopia-php/database#968 is still open, so this helper has nothing to talk to until it merges and ships.
  • Merge after #1817. Both branches append to the end of the same query templates, skills docs and e2e language suites, so they conflict with each other (31 files) even though each is independently mergeable into main. Every conflict is an append-at-EOF collision; the resolution is to keep both hunks. This branch will be re-merged with main after feat: add Query.Builder, aggregates, joins, and nested ON #1817 lands.

Expose relationship queries on generated Query classes so SDKs can
constrain populated related documents the same way as Query::relationship
in utopia-php/database.
@greptile-apps

greptile-apps Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable regression remains in the current PR changes.

Summary

Adds a Query.relationship helper across the supported generated SDKs, serializing nested filters, ordering, selection, and pagination queries for populated relationship attributes.

  • Implements language-appropriate helper APIs across PHP, TypeScript variants, Dart, Python, Ruby, Kotlin, .NET, Swift, Go, and Rust.
  • Adds generated unit and cross-language E2E coverage for the serialized relationship-query behavior.
  • Documents the helper in each supported SDK skills template.

Reviews (2) · Last reviewed commit: "chore: merge main into feat/query-relati..."

@hansi-codes

hansi-codes Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Adds Query.relationship serialization across the generated SDKs, allowing filters, ordering, selection, and pagination to be applied to populated related documents. The expanded query templates also provide fluent query builders and related query-helper coverage, with supporting documentation and unit/end-to-end tests across languages.

6 of 16 changed files were too large to include in full.

Latest changes: The newest commits add fluent query builders and broader query-helper support across the language templates, including client-side normalization or flattening for builder inputs and additional tests and examples.

Verdict New comments Fixed Still open
💬 Commented 0 0 0

Note

Part of the diff was too large to review, so Hansi did not approve.

📂 Walkthrough · 19
File Change
templates/android/library/src/main/java/io/package/Query.kt.twig, templates/kotlin/src/main/kotlin/io/appwrite/Query.kt.twig, templates/kotlin/src/test/kotlin/io/appwrite/QueryTest.kt.twig Add fluent query builders and nested relationship query serialization, with Kotlin unit coverage.
templates/dart/lib/query.dart.twig, templates/dart/lib/query/builder.dart.twig, templates/dart/test/query_test.dart.twig Add Dart query builder and query-helper coverage.
templates/deno/src/query.ts.twig, templates/deno/test/query.test.ts.twig Add Deno query builders, query normalization, and tests.
templates/dotnet/Package/Query.cs.twig, templates/dotnet/Package/Query/Builder.cs.twig Add .NET query helpers, builder support, and parameter flattening.
templates/go/query.go.twig, templates/go/query/builder.go.twig, templates/go/query_test.go.twig Add Go query helpers and fluent builder with serialization tests.
templates/php/src/Query.php.twig, templates/php/src/Query/Builder.php.twig, templates/php/tests/QueryTest.php.twig Add PHP query helpers and builder with unit coverage.
templates/python/package/query.py.twig Add Python relationship support, query builders, and query-input flattening.
templates/react-native/src/query.ts.twig, templates/web/src/query.ts.twig Add TypeScript query builders, helper coverage, and query-input normalization.
templates/ruby/lib/container/query.rb.twig, templates/ruby/lib/container/query/builder.rb.twig Add Ruby query builders and nested relationship support.
templates/rust/src/query/builder.rs.twig, templates/rust/src/query/mod.rs.twig, templates/rust/tests/tests.rs Add Rust fluent query builder support and query tests.
templates/swift/Sources/Query.swift.twig, templates/swift/Sources/Query/Builder.swift.twig Add Swift query builders and relationship query serialization.
templates/skills/dart.md.twig, templates/skills/dotnet.md.twig, templates/skills/go.md.twig, templates/skills/kotlin.md.twig, templates/skills/php.md.twig, templates/skills/python.md.twig, templates/skills/ruby.md.twig, templates/skills/rust.md.twig, templates/skills/swift.md.twig, templates/skills/typescript.md.twig Document relationship query usage and fluent builders across supported SDKs.
tests/e2e/Base.php, tests/e2e/languages/android/Tests.kt, tests/e2e/languages/apple/Tests.swift, tests/e2e/languages/dart/tests.dart, tests/e2e/languages/deno/tests.ts, tests/e2e/languages/dotnet/Tests.cs, tests/e2e/languages/flutter/tests.dart, tests/e2e/languages/go-v2/tests.go, tests/e2e/languages/go/tests.go, tests/e2e/languages/kotlin/Tests.kt, tests/e2e/languages/node/test.js, tests/e2e/languages/php/test.php, tests/e2e/languages/python/tests.py, tests/e2e/languages/react-native/browser.js, tests/e2e/languages/ruby/tests.rb, tests/e2e/languages/swift/Tests.swift, tests/e2e/languages/unity/Tests.cs, tests/e2e/languages/web/index.html, tests/e2e/languages/web/node.js Exercise relationship query serialization in language E2E suites and update shared expected output.
templates/dotnet/Package/Query.cs.twig Add the .NET relationship helper.
templates/react-native/src/query.ts.twig Add the React Native relationship helper.
templates/ruby/lib/container/query.rb.twig Add the Ruby relationship helper.
templates/swift/Sources/Query.swift.twig Add the Swift relationship helper.
templates/web/src/query.ts.twig Add the Web/Node relationship helper.
tests/e2e/Base.php Add the expected serialized relationship query output.

Reviewed the commits since 0653fc2 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@abnegate

Copy link
Copy Markdown
Member Author

Merged main in, including #1817 and #2055 (8392465).

  • Conflicts: the e2e scripts and skill docs had two additions in the same place: this PR's relationship lines and feat: add Query.Builder, aggregates, joins, and nested ON #1817's query-transport and aggregate/join blocks. Both are kept, with relationship first to match Base::QUERY_HELPER_RESPONSES. For Go query.go/query_test.go and Rust query/mod.rs (renamed from query.rs on main), I took main's version and re-added Relationship/relationship and its Go test.
  • Query.Builder: every SDK's builder from feat: add Query.Builder, aggregates, joins, and nested ON #1817 now has a relationship method alongside elemMatch (TS/Node/RN/Deno, Python, Ruby, PHP, Go, Swift, Kotlin, Android, Dart, .NET, Rust).
  • Android16Java17 failure (real): Android's relationship parsed nested queries back into Query through Gson reflection. The e2e job runs the unit tests against an R8-shrunk library, where those fields are renamed, so the nested queries were serialised empty (the e2e diff showed values[0] and values[1] with no method). It now parses them into maps, as or/and/elemMatch/having already do. The new QueryTest.relationship checks the nested queries and the builder. Running testR8UnitTest locally, it fails with the old implementation and all 35 tests pass with the fix.

Verified locally:

  • Generation suite (105 tests), Pint, Rector and Twig lint.
  • Go: vet and tests. Rust: fmt (1.83.0) and 827 tests.
  • Node: 955 tests plus format/lint/tsc. Web and React Native: format/lint/tsc.
  • PHP: 944 tests plus Pint/PHPStan/Rector.
  • .NET: format and build. Dart: 1308 tests. Swift: build. Kotlin: QueryTest.

Not checked locally (CI covers them): Black for Python and RuboCop for Ruby, because neither is installed here.

@abnegate
abnegate merged commit 4b793da into main Oct 15, 2026
61 checks passed
@abnegate
abnegate deleted the feat/query-relationship branch October 15, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant