Skip to content

Conversation

hoi4
Copy link

@hoi4 hoi4 commented Oct 14, 2025

Description

Added a new test that should currently fail due to defaults: true not working when using the grpc loader.
As mentioned here I did not quickly manage to run e2e tests without other errors, so I hope I got it right.

Fixes #5277

Copy link
Contributor

coderabbitai bot commented Oct 14, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • Updated gRPC proto loading configuration to enable sensible defaults, improving reliability and compatibility during setup.
  • Tests

    • Added an end-to-end test to verify that querying movies with no results returns an empty response as expected.

Walkthrough

Adds an e2e test covering an empty movies result via GraphQL over gRPC and updates the gRPC subgraph configuration to use a structured source with load.defaults enabled for proto loading.

Changes

Cohort / File(s) Summary
E2E test: empty results
e2e/grpc-example/grpc-example.test.ts
Adds a test "gets empty movies correctly" that composes the GraphQL output, starts an executor, runs GetMovies with HORROR/2015, and snapshots an empty dataset response.
gRPC config: structured source with defaults
e2e/grpc-example/mesh.config.ts
Changes subgraph source from string path to object: file path plus load.defaults: true to alter proto loading behavior.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test Runner
  participant C as GraphQL Executor
  participant G as gRPC Handler
  participant S as Movies gRPC Service

  T->>C: Compose schema and start executor
  T->>C: Execute GetMovies(genre=HORROR, year=2015)
  C->>G: Resolve via gRPC handler
  note right of G: Proto loaded with defaults: true
  G->>S: gRPC request: GetMovies
  S-->>G: Empty dataset response
  G-->>C: Mapped response
  C-->>T: GraphQL result (empty list)
  T->>T: Snapshot assertion
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through proto fields with cheer,
Defaults now whisper, loud and clear.
An empty reel, no screams tonight—
HORROR 2015 fades from sight.
Tests compose, assertions gleam,
Mesh and gRPC, a tidy dream. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the primary change by indicating the addition of a failing end-to-end test to reproduce the defaults issue in the gRPC loader, which matches the core purpose of the pull request.
Linked Issues Check ✅ Passed The pull request adds a failing end-to-end test that configures load.defaults: true for the gRPC loader and demonstrates that default values are not applied as expected, directly addressing issue #5277’s requirement for a failing test to reproduce the defaults bug.
Out of Scope Changes Check ✅ Passed All changes in the pull request—including the updated mesh.config.ts to enable load.defaults and the new e2e test—directly serve the goal of reproducing the defaults issue and there are no unrelated modifications outside this scope.
Description Check ✅ Passed The description concisely states that a new end-to-end test has been added to demonstrate the defaults issue in the gRPC loader and references the linked issue, aligning directly with the changes in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b1791d and 4ae879a.

⛔ Files ignored due to path filters (1)
  • e2e/grpc-example/__snapshots__/grpc-example.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • e2e/grpc-example/grpc-example.test.ts (1 hunks)
  • e2e/grpc-example/mesh.config.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
e2e/grpc-example/grpc-example.test.ts (1)
e2e/utils/tenv.ts (2)
  • compose (303-358)
  • serve (240-302)
🔇 Additional comments (1)
e2e/grpc-example/mesh.config.ts (1)

20-25: Configuration correctly enables protobuf defaults—ensure YamlConfig.GrpcHandler.source supports a structured object with file and load.defaults.

Comment on lines +18 to +40
it('gets empty movies correctly', async () => {
const { output } = await compose({ services: [movies], output: 'graphql' });
const { execute } = await serve({ supergraph: output });
// Genre HORROR does not exist in mock data
const query = /* GraphQL */ `
query GetMovies {
exampleGetMovies(input: { movie: { genre: HORROR, year: 2015 } }) {
result {
name
year
rating
cast
time {
seconds
}
}
}
}
`;
await expect(execute({ query })).resolves.toMatchSnapshot(
'get-empty-movies-grpc-example-result',
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Test scenario may not effectively demonstrate the defaults issue.

The test queries with genre: HORROR, which doesn't exist in the mock data, and expects an empty result. However, issue #5277 describes a bug where fields within returned objects have null values instead of their protobuf default values (e.g., an enum defaulting to ENUM_ZERO). An empty result set won't demonstrate this issue.

To properly test the defaults behavior, consider:

  1. Query data that exists in the mock (e.g., use genre: DRAMA like in the next test)
  2. Include fields that have protobuf defaults (especially enum fields)
  3. Assert that those fields are populated with their default values, not null

This would create a test that fails in a way that clearly demonstrates the missing defaults functionality described in the issue.

Example revision:

- it('gets empty movies correctly', async () => {
+ it('populates protobuf default values correctly', async () => {
    const { output } = await compose({ services: [movies], output: 'graphql' });
    const { execute } = await serve({ supergraph: output });
-   // Genre HORROR does not exist in mock data
+   // Query existing data to check if fields with defaults are populated
    const query = /* GraphQL */ `
      query GetMovies {
-       exampleGetMovies(input: { movie: { genre: HORROR, year: 2015 } }) {
+       exampleGetMovies(input: { movie: { genre: DRAMA, year: 2015 } }) {
          result {
            name
            year
            rating
            cast
+           genre
            time {
              seconds
            }
          }
        }
      }
    `;
    await expect(execute({ query })).resolves.toMatchSnapshot(
-     'get-empty-movies-grpc-example-result',
+     'get-movies-with-defaults-result',
    );
  });

This way, when the test snapshot is generated, you can verify whether enum fields (like genre) are set to their protobuf default values or null, directly demonstrating the issue.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('gets empty movies correctly', async () => {
const { output } = await compose({ services: [movies], output: 'graphql' });
const { execute } = await serve({ supergraph: output });
// Genre HORROR does not exist in mock data
const query = /* GraphQL */ `
query GetMovies {
exampleGetMovies(input: { movie: { genre: HORROR, year: 2015 } }) {
result {
name
year
rating
cast
time {
seconds
}
}
}
}
`;
await expect(execute({ query })).resolves.toMatchSnapshot(
'get-empty-movies-grpc-example-result',
);
});
it('populates protobuf default values correctly', async () => {
const { output } = await compose({ services: [movies], output: 'graphql' });
const { execute } = await serve({ supergraph: output });
// Query existing data to check if fields with defaults are populated
const query = /* GraphQL */ `
query GetMovies {
exampleGetMovies(input: { movie: { genre: DRAMA, year: 2015 } }) {
result {
name
year
rating
cast
genre
time {
seconds
}
}
}
}
`;
await expect(execute({ query })).resolves.toMatchSnapshot(
'get-movies-with-defaults-result',
);
});
🤖 Prompt for AI Agents
In e2e/grpc-example/grpc-example.test.ts around lines 18 to 40, the test queries
for a non-existent genre (HORROR) which returns an empty result and therefore
cannot reveal the protobuf-defaults bug; change the test to query existing mock
data (e.g., use genre: DRAMA as in the next test), include fields that have
protobuf defaults (especially enum fields and nested scalar fields), and assert
(or snapshot) that those fields are populated with their protobuf default values
instead of null so the test fails when defaults are missing.

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.

gRPC handler: load defaults option not working

2 participants