Skip to content

feat(grpc_datasource): introduce RPCTransport abstraction with gRPC implementation#1490

Merged
Noroth merged 3 commits into
wundergraph:masterfrom
fengyuwusong:feat/grpc-datasource-transport-abstraction
May 21, 2026
Merged

feat(grpc_datasource): introduce RPCTransport abstraction with gRPC implementation#1490
Noroth merged 3 commits into
wundergraph:masterfrom
fengyuwusong:feat/grpc-datasource-transport-abstraction

Conversation

@fengyuwusong
Copy link
Copy Markdown
Contributor

@fengyuwusong fengyuwusong commented May 8, 2026

@coderabbitai summary

Summary

Refactor the gRPC data source so the dial path goes through a small RPCTransport interface instead of a hard-coded grpc.ClientConnInterface dependency. This is a no-op for behaviour and a no-op for existing callers, but it lets follow-up work plug additional transports (Connect, gRPC-Web, in-memory mocks) into the same data source pipeline.

This is the first of two PRs that together replace #1480.

Related

What's changed

pkg/engine/datasource/grpc_datasource

  • New transport.go: defines the RPCTransport interface and a GRPCTransport implementation that wraps grpc.ClientConnInterface. The interface takes the same (ctx, methodFullName, input, output) shape the data source already passes to grpc.ClientConnInterface.Invoke, so swapping it in is mechanical.
  • grpc_datasource.go: DataSource now keeps an RPCTransport rather than a raw grpc.ClientConnInterface. NewDataSource accepts the abstraction; a thin convenience wrapper NewDataSourceGRPC preserves the existing call shape for callers that already have a grpc.ClientConnInterface.
  • New transport_test.go: shared helpers (newTestCompiler, findMessageDesc) plus a smoke test for GRPCTransport.Invoke. Helpers live here so the follow-up Connect transport tests can reuse them without a circular dependency.
  • grpc_datasource_test.go, grpc_datasource_federation_test.go, grpc_datasource_spy_test.go: every existing NewDataSource(conn, …) call site is migrated onto NewDataSourceGRPC(conn, …). Tests still take a grpc.ClientConnInterface directly.

pkg/engine/datasource/graphql_datasource

  • graphql_datasource.go: the planner constructed the gRPC data source inline via grpcdatasource.NewDataSource(p.grpcClient, …). With the new signature this would no longer compile, so the call switches to grpcdatasource.NewDataSourceGRPC(p.grpcClient, …). No behavioural change, no change to public Factory APIs.

Backward compatibility

  • All existing NewDataSource consumers should switch to NewDataSourceGRPC. The old function name is kept but takes the abstraction, not a grpc.ClientConnInterface.
  • No behaviour change for the gRPC dial path: GRPCTransport.Invoke simply forwards to the underlying client connection.

Testing

  • pkg/engine/datasource/grpc_datasource: existing test suite (455+ cases) passes; new TestGRPCTransport_Invoke covers the wrapper directly.
  • pkg/engine/datasource/graphql_datasource: existing tests pass against the migrated call site.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/docs-website — N/A: no public-facing API change worth surfacing in docs at this stage; user-facing docs land with the consuming cosmo PR.
  • I have read the Contributors Guide.

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

…mplementation

Pull the gRPC dial path inside the data source out from a hard-coded
*grpc.ClientConnInterface dependency to a small RPCTransport interface.
This is a no-op for behaviour, but it lets the data source dispatch
through any concrete transport in follow-up work.

  - new transport.go    : RPCTransport interface + GRPCTransport
                          implementation that wraps grpc.ClientConnInterface.
  - new transport_test.go : shared helpers (newTestCompiler, findMessageDesc)
                            plus a smoke test for GRPCTransport.Invoke.
  - grpc_datasource.go  : DataSource now keeps an RPCTransport rather than
                          a raw grpc.ClientConnInterface. NewDataSource
                          accepts the abstraction and a thin convenience
                          wrapper NewDataSourceGRPC preserves the existing
                          call shape for callers that already have a
                          grpc.ClientConnInterface.
  - grpc_datasource{,_federation,_spy}_test.go : migrate the existing
                          NewDataSource(conn, ...) call sites onto
                          NewDataSourceGRPC(conn, ...) so the tests still
                          take a grpc connection directly.
  - graphql_datasource.go : the planner constructed the gRPC data source
                          inline; switch its single NewDataSource(p.grpcClient,
                          ...) site to NewDataSourceGRPC(p.grpcClient, ...)
                          so the package compiles against the new signature.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec65926d-15d3-41ef-8232-c4ac9bba870a

📥 Commits

Reviewing files that changed from the base of the PR and between 3b64f82 and d16cca0.

📒 Files selected for processing (5)
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_federation_test.go
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_spy_test.go
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_test.go
💤 Files with no reviewable changes (1)
  • v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go

📝 Walkthrough

Walkthrough

This PR introduces an RPCTransport interface and grpcTransport adapter, refactors grpcdatasource.DataSource to store and use an RPCTransport (constructor accepts RPCTransport), updates Load to call transport.Invoke, adds transport tests, and updates GraphQL wiring and all gRPC datasource tests to wrap connections with NewGRPCTransport.

Changes

gRPC Datasource Transport Abstraction

Layer / File(s) Summary
Transport Interface & Implementation
v2/pkg/engine/datasource/grpc_datasource/transport.go
Introduces RPCTransport interface with Invoke(ctx, methodFullName, input, output) and a grpcTransport adapter with NewGRPCTransport that delegates to grpc.ClientConnInterface.Invoke.
Transport Tests
v2/pkg/engine/datasource/grpc_datasource/transport_test.go
Adds newTestCompiler, findMessageDesc, and TestGRPCTransport_Invoke smoke test asserting NewGRPCTransport(mi).Invoke(...) succeeds with dynamic protobuf messages.
DataSource Struct & Load Refactor
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go
Replaces internal cc grpc.ClientConnInterface with transport RPCTransport; NewDataSource now accepts an RPCTransport; Load performs RPCs using d.transport.Invoke(...).
GraphQL Datasource Integration
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go
ConfigureFetch updated to call NewDataSource with NewGRPCTransport(p.grpcClient) when constructing a gRPC-backed datasource.
Federation Test Updates
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_federation_test.go
Five federation/entity-loading tests updated to pass NewGRPCTransport(conn) into NewDataSource; test behavior unchanged.
Spy Test Updates
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_spy_test.go
Four spy tests updated to wrap conn with NewGRPCTransport when creating DataSource; assertions about RPC calls unchanged.
Comprehensive Test & Benchmark Updates
v2/pkg/engine/datasource/grpc_datasource/grpc_datasource_test.go
Many tests and benchmarks updated to construct DataSource with NewGRPCTransport(...) across diverse test scenarios; no other config changes at call sites.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: introducing an RPCTransport abstraction for the gRPC datasource with a gRPC implementation.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the refactoring's purpose, structure, and impact across multiple files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment thread v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go Outdated
Per review feedback, remove the NewDataSourceGRPC convenience wrapper to
avoid proliferating per-client constructors. Callers now compose explicitly:
NewDataSource(NewGRPCTransport(conn), config).
@fengyuwusong
Copy link
Copy Markdown
Contributor Author

fengyuwusong commented May 21, 2026

Hi @Noroth, I've addressed your review feedback in the latest commit (d16cca0):

Could you please take another look? Thanks!

@Noroth Noroth merged commit faffd81 into wundergraph:master May 21, 2026
10 checks passed
@fengyuwusong fengyuwusong deleted the feat/grpc-datasource-transport-abstraction branch May 21, 2026 08:39
ysmolski pushed a commit that referenced this pull request May 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.4.0](v2.3.1...v2.4.0)
(2026-05-21)


### Features

* **grpc_datasource:** introduce RPCTransport abstraction with gRPC
implementation
([#1490](#1490))
([faffd81](faffd81))


### Bug Fixes

* use remapped variables in cost calculation
([#1505](#1505))
([972ad0f](972ad0f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

2 participants