Skip to content

Commit 91096a7

Browse files
committed
refactor and addressing PR review comments
1 parent 7d182ec commit 91096a7

30 files changed

+1732
-1509
lines changed

protographic/src/operation-to-proto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,12 @@ class OperationsToProtoVisitor {
268268
// This ensures exact matching between GraphQL operation names and RPC method names
269269
// PascalCase: starts with uppercase, contains at least one lowercase letter
270270
if (!/^[A-Z](?=.*[a-z])[a-zA-Z0-9]*$/.test(operationName)) {
271+
const suggestedName = upperFirst(camelCase(operationName));
271272
throw new Error(
272273
`Operation name "${operationName}" must be in PascalCase ` +
273274
`(start with uppercase letter, followed by mixed-case letters/numbers). ` +
274275
`Examples: GetUser, CreatePost, OnMessageAdded. ` +
276+
`Suggested name: "${suggestedName}". ` +
275277
`This ensures the RPC method name exactly matches the GraphQL operation name.`,
276278
);
277279
}

router-tests/connectrpc/README.md

Lines changed: 0 additions & 56 deletions
This file was deleted.

router-tests/connectrpc/connectrpc_server_lifecycle_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,12 @@ func TestConnectRPC_ServerLifecycle_StartStopReload(t *testing.T) {
8282
func TestConnectRPC_ServerLifecycle_ErrorScenarios(t *testing.T) {
8383
t.Parallel()
8484

85-
t.Run("start fails with invalid proto directory", func(t *testing.T) {
86-
server, err := connectrpc.NewServer(connectrpc.ServerConfig{
85+
t.Run("NewServer fails with invalid proto directory", func(t *testing.T) {
86+
_, err := connectrpc.NewServer(connectrpc.ServerConfig{
8787
ServicesDir: "/nonexistent/path",
8888
GraphQLEndpoint: "http://localhost:4000/graphql",
8989
Logger: zap.NewNop(),
9090
})
91-
require.NoError(t, err)
92-
93-
err = server.Start()
9491
assert.Error(t, err)
9592
assert.Contains(t, err.Error(), "failed to discover services")
9693
})
@@ -147,19 +144,22 @@ func TestConnectRPC_Server_GetServiceInfo(t *testing.T) {
147144
t.Run("returns consistent service count and names", func(t *testing.T) {
148145
ts := NewTestConnectRPCServer(t, ConnectRPCServerOptions{})
149146

150-
// Before start
151-
assert.Equal(t, 0, ts.GetServiceCount())
152-
assert.Empty(t, ts.GetServiceNames())
153-
154-
err := ts.Start()
155-
require.NoError(t, err)
156-
157-
// After start - verify count and names are consistent
147+
// Services are loaded during NewServer, so they should be available immediately
158148
count := ts.GetServiceCount()
159149
names := ts.GetServiceNames()
160150

161-
assert.GreaterOrEqual(t, count, 1, "should have at least one service")
151+
assert.GreaterOrEqual(t, count, 1, "should have at least one service after NewServer")
162152
assert.Len(t, names, count, "service names length should match count")
163153
assert.NotEmpty(t, names, "service names should not be empty")
154+
155+
err := ts.Start()
156+
require.NoError(t, err)
157+
158+
// After start - verify count and names remain consistent
159+
countAfterStart := ts.GetServiceCount()
160+
namesAfterStart := ts.GetServiceNames()
161+
162+
assert.Equal(t, count, countAfterStart, "service count should remain the same after Start")
163+
assert.ElementsMatch(t, names, namesAfterStart, "service names should remain the same after Start")
164164
})
165165
}

router-tests/testdata/connectrpc/README.md

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,32 @@
22

33
This directory contains Protocol Buffer definitions and GraphQL operations for ConnectRPC integration tests.
44

5-
## Directory Structure
5+
## Writing New Tests
66

7-
```
8-
router-tests/testdata/connectrpc/
9-
├── services/ # Proto service definitions and GraphQL operations
10-
│ └── employee.v1/ # Employee service v1
11-
│ ├── service.proto # Proto service definition
12-
│ ├── QueryGetEmployeeById.graphql # GraphQL query operation
13-
│ ├── QueryGetEmployeeByPets.graphql # GraphQL query operation
14-
│ ├── QueryGetEmployees.graphql # GraphQL query operation
15-
│ ├── QueryGetEmployeesByPetsInlineFragment.graphql
16-
│ ├── QueryGetEmployeesByPetsNamedFragment.graphql
17-
│ ├── QueryGetEmployeeWithMood.graphql # GraphQL query operation
18-
│ └── MutationUpdateEmployeeMood.graphql # GraphQL mutation operation
19-
├── client/ # Generated client code (committed to repo)
20-
│ └── employee/
21-
│ └── v1/
22-
│ ├── employeev1connect/ # Connect RPC client
23-
│ └── service.pb.go # Protobuf types
24-
├── buf.yaml # Buf configuration
25-
├── buf.gen.yaml # Buf code generation config
26-
└── README.md # This file
27-
```
28-
29-
## Purpose
7+
To add a new service for testing:
308

31-
These proto files and GraphQL operations are used by the ConnectRPC server to:
32-
1. **Discover services** - Parse proto files to identify RPC services and methods
33-
2. **Load operations** - Read GraphQL operations that correspond to each RPC method
34-
3. **Generate handlers** - Create HTTP handlers that translate RPC calls to GraphQL requests
9+
1. Create a new directory under `services/` (e.g., `services/myservice.v1/`)
10+
2. Add your `.proto` file with service definitions - or generate it with `wgc grpc-service generate`
11+
3. Add corresponding `.graphql` files (GraphQL Executable Operations) for each RPC method
12+
4. The ConnectRPC server will automatically discover and load them
3513

36-
## Testing
14+
### Example Structure
3715

38-
The integration tests verify:
39-
- **Service discovery** (`router-tests/connectrpc_test.go`) - Proto files are correctly parsed and services are registered
40-
- **Operation loading** - GraphQL operations are loaded and associated with RPC methods
41-
- **Server lifecycle** - Server can start, reload, and stop correctly
42-
- **Router integration** - ConnectRPC works with the main router testenv
43-
- **E2E protocol tests** (`router-tests/connectrpc_client_test.go`) - All three RPC protocols (Connect, gRPC, gRPC-Web) work correctly
44-
- **Error handling** - GraphQL errors and HTTP status codes are properly mapped to Connect error codes
45-
- **Concurrency** - Multiple simultaneous requests are handled correctly
16+
```
17+
services/
18+
└── myservice.v1/
19+
├── service.proto # Proto service definition
20+
├── QueryGetItem.graphql # GraphQL query operation
21+
└── MutationCreateItem.graphql # GraphQL mutation operation
22+
```
4623

4724
## Regenerating Client Code
4825

49-
The `client/` directory contains generated client code used by the E2E tests. This code is **committed to the repository** to ensure tests work without requiring buf to be installed.
26+
The `client/` directory contains generated client code used by E2E tests. This code is **committed to the repository**.
5027

5128
### When to Regenerate
5229

53-
You need to regenerate the client code when:
30+
Regenerate when:
5431
- Proto service definitions are modified (`services/*/service.proto`)
5532
- GraphQL operations are added, removed, or modified (`services/*/*.graphql`)
56-
- Message types are changed in proto files
57-
58-
## Adding New Services
59-
60-
To add a new service for testing:
61-
62-
1. Create a new directory under `services/` (e.g., `services/myservice.v1/`)
63-
2. Add corresponding `.graphql` files (GraphQL Executable Operations)
64-
3. Add your `.proto` file with service definitions - or generate it with `wgc grpc-service generate`
65-
4. The ConnectRPC server will automatically discover and load them if configured to do so
33+
- Message types are changed in proto files

router-tests/testdata/connectrpc/buf.gen.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ managed:
55
- file_option: go_package_prefix
66
value: github.com/wundergraph/cosmo/router-tests/testdata/connectrpc/client
77
plugins:
8-
- remote: buf.build/protocolbuffers/go
8+
- local: protoc-gen-go
99
out: client
1010
opt:
1111
- paths=source_relative
12-
- remote: buf.build/connectrpc/go
12+
- local: protoc-gen-connect-go
1313
out: client
1414
opt:
15-
- paths=source_relative
15+
- paths=source_relative

router-tests/testdata/connectrpc/client/employee.v1/employeev1connect/service.connect.go

Lines changed: 26 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)