Skip to content

fix: do not create lookups for non resolvable keys#2175

Merged
Noroth merged 4 commits intomainfrom
ludwig/eng-8005-should-not-generate-rpc-methods-for-non-resolvable-entities
Aug 28, 2025
Merged

fix: do not create lookups for non resolvable keys#2175
Noroth merged 4 commits intomainfrom
ludwig/eng-8005-should-not-generate-rpc-methods-for-non-resolvable-entities

Conversation

@Noroth
Copy link
Copy Markdown
Contributor

@Noroth Noroth commented Aug 28, 2025

Summary by CodeRabbit

  • New Features

    • Adds support for the GraphQL Federation @key resolvable flag.
    • Lookup RPCs and related messages are now generated only for resolvable keys; non-resolvable keys are skipped.
    • Composite keys are supported, with generation occurring when the directive is resolvable.
    • Defaults to generating lookups when resolvable is not specified (treated as true).
  • Tests

    • Introduces test coverage for resolvable/non-resolvable key scenarios, including composite keys and resulting service/messaging structures.

Checklist

@Noroth Noroth requested a review from StarpTech as a code owner August 28, 2025 09:44
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 28, 2025

Walkthrough

Introduces 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

Cohort / File(s) Summary
Key directive handling and lookup generation
protographic/src/sdl-to-proto-visitor.ts
Adds KeyDirective interface; replaces getKeyFromDirective with getKeyInfoFromDirective returning { keyString, resolvable }. Updates key processing to skip non-resolvable keys and use keyString for normalization and RPC/message generation. Adjusts documentation/comments accordingly.
Federation tests for resolvable behavior
protographic/tests/sdl-to-proto/04-federation.test.ts
Adds tests validating proto generation based on @key resolvable flag: no lookup RPCs when resolvable: false; lookup generation when resolvable: true or unspecified. Asserts service/method names, request/response, and key messages via snapshots.

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
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stale getKeyFromDirective usage in mapping visitor
In protographic/src/sdl-to-mapping-visitor.ts, update both the call at line 122 and any others to use getKeyInfoFromDirective (handling its { keyString, resolvable } return) and remove the old private getKeyFromDirective definition 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.

📥 Commits

Reviewing files that changed from the base of the PR and between ca1861b and 4b4b9be.

📒 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.

Comment thread protographic/src/sdl-to-proto-visitor.ts
Copy link
Copy Markdown
Contributor

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Noroth Noroth merged commit bbf5695 into main Aug 28, 2025
8 checks passed
@Noroth Noroth deleted the ludwig/eng-8005-should-not-generate-rpc-methods-for-non-resolvable-entities branch August 28, 2025 12:44
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants