Conversation
WalkthroughIntroduces a KeyDirective interface and replaces key extraction with a structured getKeyInfoFromDirective helper. Key-lookup generation now filters by the resolvable flag, affecting which RPCs/messages are emitted. Adds tests covering resolvable: true/false and default behavior, verifying generated proto services and messages. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
protographic/src/sdl-to-proto-visitor.ts (2)
603-616: Guard against empty/invalid key strings to prevent malformed lookups.If a directive omits fields or yields an empty string, we may currently add an empty normalized key, producing invalid method names/messages. Skip such cases early.
- for (const keyDirective of keyDirectives) { - const keyInfo = this.getKeyInfoFromDirective(keyDirective); - if (!keyInfo) continue; - - const { keyString, resolvable } = keyInfo; - if (!resolvable) continue; - - const normalizedKey = keyString - .split(/[,\s]+/) - .filter((field) => field.length > 0) - .sort() - .join(' '); - - normalizedKeysSet.add(normalizedKey); - } + for (const keyDirective of keyDirectives) { + const keyInfo = this.getKeyInfoFromDirective(keyDirective); + if (!keyInfo) continue; + + const { keyString, resolvable } = keyInfo; + if (!resolvable) continue; + + const trimmed = keyString.trim(); + if (trimmed.length === 0) continue; + + const parts = trimmed.split(/[,\s]+/).filter((f) => f.length > 0); + if (parts.length === 0) continue; + + const normalizedKey = parts.sort().join(' '); + normalizedKeysSet.add(normalizedKey); + }
574-646: Replace stalegetKeyFromDirectiveusage in mapping visitor
Inprotographic/src/sdl-to-mapping-visitor.ts, update both the call at line 122 and any others to usegetKeyInfoFromDirective(handling its{ keyString, resolvable }return) and remove the oldprivate getKeyFromDirectivedefinition at line 175.
🧹 Nitpick comments (2)
protographic/tests/sdl-to-proto/04-federation.test.ts (2)
854-903: Good negative-case coverage for non-resolvable keys.This verifies no Lookup RPCs/messages are emitted when all keys are non-resolvable. Consider adding one more assertion ensuring the proto contains no “Lookup” substrings as a quick guard against accidental emissions outside snapshots.
- expect(protoText).toMatchInlineSnapshot(` + expect(protoText).not.toMatch(/\\bLookup[A-Za-z]+\\b/); + expect(protoText).toMatchInlineSnapshot(`
993-1079: Default resolvable behavior covered.When not specified, resolvable defaults to true and generates the expected lookup. Consider adding a case where the same key appears twice with resolvable true/false to ensure deduplication + preference for the resolvable instance.
Example additional test (can live in this file):
test('dedup identical keys with mixed resolvable flags', () => { const sdl = ` scalar openfed__FieldSet directive @key(fields: openfed__FieldSet!, resolvable: Boolean = true) repeatable on INTERFACE | OBJECT type P @key(fields: "a b", resolvable: false) @key(fields: "b a", resolvable: true) { a: ID! b: ID! } type Query { ps: [P!]! } `; const { proto } = compileGraphQLToProto(sdl); expectValidProto(proto); // Only one lookup, sorted as a and b expect(proto).toMatch(/rpc LookupPByAAndB\\(/); expect(proto.match(/rpc LookupPByAAndB\\(/g)?.length).toBe(1); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
protographic/src/sdl-to-proto-visitor.ts(3 hunks)protographic/tests/sdl-to-proto/04-federation.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
protographic/tests/sdl-to-proto/04-federation.test.ts (2)
protographic/src/index.ts (1)
compileGraphQLToProto(53-79)protographic/tests/util.ts (1)
expectValidProto(29-31)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
protographic/tests/sdl-to-proto/04-federation.test.ts (2)
845-852: Snapshot alignment with field naming (snake_case) looks correct.Product fields correctly map to snake_case and keep stable numbering. No action needed.
905-991: Positive-case coverage for mixed resolvable flags is solid.Only the resolvable composite key generates Lookup RPCs/messages. Nice.
protographic/src/sdl-to-proto-visitor.ts (1)
99-106: Introducing KeyDirective shape is appropriate and scoped.Internal interface keeps the intent clear and avoids leaking to public API. LGTM.
…ods-for-non-resolvable-entities
…ods-for-non-resolvable-entities
…ods-for-non-resolvable-entities
Summary by CodeRabbit
New Features
Tests
Checklist