Replace RPC string dispatch with direct service trait calls in GraphQL#216
Merged
Replace RPC string dispatch with direct service trait calls in GraphQL#216
Conversation
GraphQL resolvers now call service methods directly via an `Arc<Services>` bundle instead of going through the string-based `ServiceCaller` dispatch. This eliminates the `GatewayServiceCaller` (~350-line match block) and the `rpc_call!`/`rpc_json_call!` macros, making both GraphQL and RPC share the exact same service trait objects with zero indirection. Key changes: - Add `Services` bundle struct and `SystemInfoService` trait to moltis-service-traits for shared service access - Replace `ServiceCaller` trait with direct `Arc<Services>` in GqlContext - Rewrite all query/mutation resolvers to call services directly - Add `GatewaySystemInfoService` for gateway-state queries (health, status, presence, nodes, hooks, heartbeat) - Add `GatewayServices::to_services()` to bridge gateway into the shared Services bundle - Update integration tests with per-trait mock implementations https://claude.ai/code/session_01Kof5A1V5HD5eHjs6Q8kdGb
Contributor
Merging this PR will improve performance by 76.43%
Performance Changes
Comparing Footnotes
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Break the 6092-line methods.rs monolith into focused submodules: - methods/mod.rs: types, authorization, MethodRegistry, tests - methods/gateway.rs: gateway-internal handlers (health, status, presence, heartbeat) - methods/node.rs: node handlers (list, describe, rename, invoke, events) - methods/pairing.rs: pairing handlers (pair request/approve/reject, device tokens) - methods/services.rs: service-delegating handlers (agent, sessions, chat, channels, config, cron, heartbeat, models, providers, skills, mcp, voice, memory, hooks) - methods/voice.rs: voice provider detection, ElevenLabs catalog, provider settings Also applies rustfmt to graphql crate files. https://claude.ai/code/session_01Kof5A1V5HD5eHjs6Q8kdGb
316c8a2 to
413419c
Compare
The test was racing with kimi_headers_contain_required_fields on the shared ~/.config/moltis/kimi_device_id file, causing intermittent CI failures. Extract path-parameterized helper and use tempdir in tests.
413419c to
1f47fe3
Compare
filter({ hasText: "OpenAI" }) is a substring match that also picks up
"OpenAI Codex" (OAuth), causing tests to click the wrong provider.
Use exact regex/text matching on the provider name element instead.
Also make moveToVoiceStep return false on timeout instead of crashing,
so the voice badge test skips gracefully when the step is unreachable.
…ql-rpc-RjkWZ # Conflicts: # crates/web/ui/e2e/specs/onboarding.spec.js # crates/web/ui/e2e/specs/providers.spec.js
…ql-rpc-RjkWZ # Conflicts: # crates/gateway/src/graphql_routes.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the GraphQL resolver layer to call domain services directly through the
Servicestrait bundle instead of using string-based RPC dispatch. This eliminates theServiceCallerindirection and aligns GraphQL with the same code path used by the RPC layer.Key Changes
rpc_call!andrpc_json_call!macros with direct service method calls viaservices!(ctx)helperSystemInfoServicetrait: Extracted gateway-level system information methods (health, status, presence, nodes, heartbeat) into a dedicated service trait, replacing ad-hoc RPC dispatchfrom_service()andfrom_service_json()helpersMockCallerwith a centralMockDispatchand individual mock service structs implementing each service trait, preserving test compatibilityGraphQLContextto holdServicesbundle directly instead ofServiceCaller, and updated schema builder to inject servicesGatewaySystemInfoServiceto provide gateway-internal state to the GraphQL layer without exposing internalsImplementation Details
Servicesbundle frommoltis-service-traitsis now injected into GraphQL context and used by all resolversGatewaySystemInfoServicewhich reads fromGatewayStatefrom_service()helpersNoopSkillsStub,NoopSystemInfoService) provide sensible defaults for services not configured in all contextsThis change improves type safety, reduces string-based dispatch overhead, and makes the code path consistent between GraphQL and RPC layers.
https://claude.ai/code/session_01Kof5A1V5HD5eHjs6Q8kdGb