@@ -50,11 +50,7 @@ Use operations-based generation when:
5050- You have a large GraphQL schema but only use a subset of it
5151- You want proto definitions that exactly match your client operations
5252- You need to maintain multiple proto versions for different clients
53-
54- Use SDL-based generation when:
55- - You want a complete proto representation of your GraphQL schema
56- - You're building a general-purpose gRPC service
57- - You need to support arbitrary queries at runtime
53+ - You're working with trusted documents or persisted operations
5854
5955---
6056
@@ -84,27 +80,9 @@ query {
8480
8581Anonymous operations will throw an error during compilation.
8682
87- ### Generation Modes
88-
89- #### SDL-Based Mode (Default)
90-
91- Generates proto from the complete GraphQL schema definition:
92-
93- ``` bash
94- wgc grpc-service generate my-service \
95- --input schema.graphql \
96- --output ./proto
97- ```
98-
99- ** Generates:**
100- - Complete proto messages for all GraphQL types
101- - All fields from the schema
102- - ` mapping.json ` for runtime query translation
103- - ` service.proto.lock.json ` for field number stability
83+ ### How It Works
10484
105- #### Operations-Based Mode
106-
107- Generates proto from GraphQL operation files:
85+ The compiler generates proto from GraphQL operation files:
10886
10987``` bash
11088wgc grpc-service generate MyService \
@@ -140,8 +118,8 @@ Protocol Buffers require stable field numbers to maintain backward compatibility
140118
141119gRPC supports idempotency levels to indicate whether operations have side effects:
142120
143- - ** NO_SIDE_EFFECTS** : Safe to retry, doesn't modify state (GET-like)
144- - ** DEFAULT** : May have side effects, retry with caution (POST-like)
121+ - ** NO_SIDE_EFFECTS** : Safe to retry, doesn't modify state
122+ - ** DEFAULT** : May have side effects, retry with caution
145123
146124The ` queryIdempotency ` option explicitly sets the idempotency level for all Query operations:
147125
@@ -200,15 +178,6 @@ wgc grpc-service generate [name] [options]
200178| Option | Description |
201179| --------| -------------|
202180| ` -g, --go-package <name> ` | Adds ` option go_package ` to the proto file |
203- | ` --java-package <name> ` | Adds ` option java_package ` to the proto file |
204- | ` --java-outer-classname <name> ` | Adds ` option java_outer_classname ` to the proto file |
205- | ` --java-multiple-files ` | Adds ` option java_multiple_files = true ` to the proto file |
206- | ` --csharp-namespace <name> ` | Adds ` option csharp_namespace ` to the proto file |
207- | ` --ruby-package <name> ` | Adds ` option ruby_package ` to the proto file |
208- | ` --php-namespace <name> ` | Adds ` option php_namespace ` to the proto file |
209- | ` --php-metadata-namespace <name> ` | Adds ` option php_metadata_namespace ` to the proto file |
210- | ` --objc-class-prefix <name> ` | Adds ` option objc_class_prefix ` to the proto file |
211- | ` --swift-prefix <name> ` | Adds ` option swift_prefix ` to the proto file |
212181
213182### Examples
214183
@@ -251,18 +220,6 @@ wgc grpc-service generate UserService \
251220 --go-package github.com/myorg/myapp/proto/user/v1
252221```
253222
254- #### With Multiple Language Options
255-
256- ``` bash
257- wgc grpc-service generate UserService \
258- --input schema.graphql \
259- --output ./proto \
260- --with-operations ./operations \
261- --go-package github.com/myorg/myapp/proto/user/v1 \
262- --java-package com.myorg.myapp.proto.user.v1 \
263- --java-multiple-files \
264- --csharp-namespace MyOrg.MyApp.Proto.User.V1
265- ```
266223
267224---
268225
@@ -591,22 +548,6 @@ Regenerate - the lock file preserves existing field numbers and assigns the next
591548
592549## Advanced Topics
593550
594- ### Multi - Language Support
595-
596- Generate proto files optimized for multiple languages :
597-
598- ` ` ` bash
599- wgc grpc-service generate UserService \
600- --input schema.graphql \
601- --with-operations ./operations \
602- --output ./proto \
603- --go-package github.com/myorg/myapp/proto/user/v1 \
604- --java-package com.myorg.myapp.proto.user.v1 \
605- --java-outer-classname UserServiceProto \
606- --java-multiple-files \
607- --csharp-namespace MyOrg.MyApp.Proto.User.V1 \
608- --swift-prefix MSU
609- ` ` `
610551
611552### Custom Scalar Mappings
612553
@@ -662,9 +603,10 @@ No GraphQL operation files (.graphql, .gql) found in ./operations
662603```
663604
664605**Solution:**
665- - Ensure your operation files have `.graphql` or `.gql ` extensions
606+ - Ensure your operation files have `.graphql`, `.gql`, `.graphqls`, or `.gqls ` extensions
666607- Check the path to your operations directory
667608- Verify files contain valid GraphQL operations
609+ - Note: Only files in the top-level directory are read; subdirectories are not traversed
668610
669611#### Anonymous Operations Not Supported
670612
@@ -705,36 +647,6 @@ Field number conflict in message X
705647
706648---
707649
708- ## Best Practices
709-
710- ### Operation Organization
711-
712- 1 . ** One Operation Per File** : Makes operations easier to find and manage
713- 2 . ** Descriptive Names** : Use clear, descriptive operation names
714- 3 . ** Group by Feature** : Organize operations by feature or domain
715-
716- ** Example structure:**
717-
718- ```
719- operations/
720- ├── users/
721- │ ├── get-user.graphql
722- │ ├── list-users.graphql
723- │ └── create-user.graphql
724- ├── posts/
725- │ ├── get-post.graphql
726- │ └── list-posts.graphql
727- └── fragments/
728- ├── user-fields.graphql
729- └── post-fields.graphql
730- ```
731-
732- ### Field Naming
733-
734- 1 . ** Use snake_case** : Proto convention uses snake_case for fields
735- 2 . ** Be Consistent** : Match your GraphQL naming conventions
736- 3 . ** Avoid Reserved Words** : Don't use proto reserved words
737-
738650### Version Management
739651
7406521 . ** Semantic Versioning** : Use semver for proto packages
@@ -744,53 +656,6 @@ operations/
744656
745657---
746658
747- ## FAQ
748-
749- ### Q: Can I mix SDL-based and operations-based generation?
750-
751- ** A:** No, you must choose one mode per service. However, you can have multiple services, each using different modes.
752-
753- ### Q: What happens to unused types in operations-based mode?
754-
755- ** A:** Unused types are not included in the generated proto. Only types referenced in your operations are generated.
756-
757- ### Q: Can I use the same lock file for both modes?
758-
759- ** A:** No, lock files are mode-specific. SDL-based and operations-based modes generate different message structures.
760-
761- ### Q: How do I handle breaking changes?
762-
763- ** A:**
764- 1 . Version your proto package (e.g., ` v1 ` → ` v2 ` )
765- 2 . Generate new proto with a new package name
766- 3 . Maintain both versions during migration
767- 4 . Deprecate old version after migration
768-
769- ### Q: Can I customize the generated proto?
770-
771- ** A:** The generated proto should not be manually edited. Instead:
772- - Modify your GraphQL operations
773- - Use CLI options for language-specific settings
774- - Regenerate the proto
775-
776- ### Q: How do I handle large schemas?
777-
778- ** A:** Operations-based generation is ideal for large schemas:
779- - Only generates what you use
780- - Smaller proto files
781- - Faster compilation
782- - Better performance
783-
784- ### Q: Why must operations be named?
785-
786- ** A:** Named operations are required because:
787- - The operation name becomes the RPC method name in the proto
788- - It enables clear, semantic API definitions
789- - It supports proto reversibility (reconstructing GraphQL from proto)
790- - It follows GraphQL best practices for production applications
791-
792- ---
793-
794659## Limitations
795660
796661- ** Named operations only** : All operations must have a name. Anonymous operations are not supported
0 commit comments