|
2 | 2 |
|
3 | 3 | This directory contains Protocol Buffer definitions and GraphQL operations for ConnectRPC integration tests. |
4 | 4 |
|
5 | | -## Directory Structure |
| 5 | +## Writing New Tests |
6 | 6 |
|
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: |
30 | 8 |
|
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 |
35 | 13 |
|
36 | | -## Testing |
| 14 | +### Example Structure |
37 | 15 |
|
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 | +``` |
46 | 23 |
|
47 | 24 | ## Regenerating Client Code |
48 | 25 |
|
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**. |
50 | 27 |
|
51 | 28 | ### When to Regenerate |
52 | 29 |
|
53 | | -You need to regenerate the client code when: |
| 30 | +Regenerate when: |
54 | 31 | - Proto service definitions are modified (`services/*/service.proto`) |
55 | 32 | - 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 |
0 commit comments