cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

feat: generate proto from operations and sdl

Open asoorm opened this issue 1 month ago • 2 comments

This adds the ability to collect GraphQL operations (queries/mutations) and emit .proto files so we can auto-generate servers and clients (via gRPC/Buf Connect) to consume the graph.

  • Added compileOperationsToProto function to map GraphQL operations -> protobuf AST -> proto text.
  • Introduced a new CLI flag --with-operations that selects operations-based generation mode.
  • field-number management (via a lock/manager) to avoid collisions and ensure deterministic ordering.
  • fragment-denormalization support: named fragments and inline fragments are resolved
  • Query operations now optionally support an --idempotent-queries flag to mark queries as having no side-effects (mapped to option idempotency_level = NO_SIDE_EFFECTS; in the generated proto).

Backwards compatibility Existing schema-type-based generation unchanged. New mode opt-in.

Summary by CodeRabbit

  • New Features

    • Alpha: generate protos from GraphQL operation files via --with-operations; per-file processing and merged output.
    • Language-specific protobuf options (Java, C#, Ruby, PHP, Objective‑C, Swift) and prefixing of operation names.
    • Custom scalar mappings, maxDepth control, and query idempotency levels.
  • Documentation

    • New Operations-to-Proto guide and README updates with examples and usage notes.
  • Tests

    • Extensive tests for operations, field-number stability, fragments, enums, validation, and recursion protection.
  • Quality

    • Improved CLI validation and clearer warnings/errors and generation output.

asoorm avatar Oct 24 '25 18:10 asoorm