Skip to content

Conversation

@Aenimus
Copy link
Member

@Aenimus Aenimus commented Sep 19, 2025

Summary by CodeRabbit

  • New Features

    • Composition now produces both server and client GraphQL SDL outputs; client SDL preserves directives for tooling compatibility.
  • Documentation

    • Clarified that the client schema includes @OneOf (in addition to @deprecated and @semanticNonNull).
  • Refactor

    • Updated schema printing to retain directives in the client SDL output.
  • Tests

    • Tests updated to assert both server and client SDLs, include a shared schema header, and use a QUERY constant for type references.

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.
  • Documentation has been updated on https://github.com/wundergraph/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link

coderabbitai bot commented Sep 19, 2025

Walkthrough

Comment-only update to include @oneOf in client directives. Tests replace hard-coded 'Query' with exported QUERY and now assert both server and client federated SDLs. Composer prints the client schema using printSchemaWithDirectives and adjusts related imports. A test constant schemaDefinition was added to expected SDLs.

Changes

Cohort / File(s) Summary of changes
Schema utilities comment update
composition/src/schema-building/utils.ts
Comment updated to list @deprecated, @oneOf, and @semanticNonNull as client schema directives; no behavioral changes.
Tests: directives & QUERY constant
composition/tests/v1/directives/authorization-directives.test.ts
Tests now import/use exported QUERY constant instead of literal 'Query'; federation test helpers destructure and assert both federatedGraphSchema (server) and federatedGraphClientSchema (client); minor formatting.
Tests: shared SDL header
controlplane/test/contracts.test.ts
Introduced schemaDefinition constant and prefixed expected client SDL strings with explicit schema { ... } headers and adjusted formatting in multiple assertions.
Composer: client schema printing with directives
controlplane/src/core/composition/composer.ts
Replaced printSchema usage with printSchemaWithDirectives for the client schema output; removed unused printSchema import; moved/aliased ComposedSubgraph import to IComposedSubgraph; kept DocumentNode, GraphQLSchema, and parse imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "fix: print client schema with select directives" succinctly and accurately captures the main change: the client SDL is now printed with selected directives (code switches to printSchemaWithDirectives and tests assert a federatedGraphClientSchema that includes directives). It is concise, relevant, and conveys the primary fix for reviewers scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings

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

Copy link

@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: 0

🧹 Nitpick comments (1)
composition/tests/v1/directives/authorization-directives.test.ts (1)

529-529: Minor: Comment capitalization inconsistency.

The header was changed from "Federation Tests" to "Federation tests" - consider keeping consistent capitalization with other test group headers in the codebase.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e219ab and d00d770.

📒 Files selected for processing (1)
  • composition/tests/v1/directives/authorization-directives.test.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
composition/tests/v1/directives/authorization-directives.test.ts (4)
composition/tests/utils/utils.ts (3)
  • federateSubgraphsSuccess (59-72)
  • schemaToSortedNormalizedString (27-29)
  • normalizeString (19-21)
composition/src/router-compatibility-version/router-compatibility-version.ts (1)
  • ROUTER_COMPATIBILITY_VERSION_ONE (3-3)
composition/src/utils/string-constants.ts (1)
  • QUERY (115-115)
composition/tests/v1/utils/utils.ts (1)
  • schemaQueryDefinition (94-97)
⏰ 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). (4)
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
  • GitHub Check: build_push_image
  • GitHub Check: build_test
🔇 Additional comments (6)
composition/tests/v1/directives/authorization-directives.test.ts (6)

8-8: LGTM: Consistent usage of exported constant.

The import of the QUERY constant aligns with the goal of using centralized string constants instead of hardcoded values.


531-534: LGTM: Enhanced test structure with client schema validation.

The destructuring now includes federatedGraphClientSchema, which aligns with the PR objective of testing client schema generation with directives. This provides comprehensive validation of both server and client schema outputs.


535-544: LGTM: Usage of QUERY constant in field configurations.

Replacing the hardcoded 'Query' string with the QUERY constant improves maintainability and consistency across the codebase.


563-578: LGTM: Client schema assertion validates directive exclusion.

The new assertion for federatedGraphClientSchema correctly validates that the client schema excludes authorization directives (@authenticated) while preserving the core type structure. This aligns with the expected behavior where client schemas should not include server-side authorization directives.


582-585: LGTM: Consistent pattern for client schema validation.

The second test follows the same pattern as the first, properly destructuring federatedGraphClientSchema and validating that client schemas exclude @requiresScopes directives while maintaining type definitions. This comprehensive testing approach ensures both server and client schemas are correctly generated.

Also applies to: 614-629


531-578: Client schema should include only persisted directives — current tests are correct.

Confirmed: composition/src/schema-building/utils.ts filters persisted client directives (only @deprecated, @OneOf, @semanticNonNull); one-of tests expect @OneOf in the client schema and the authorization test correctly omits @authenticated. No change required.

Copy link

@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: 0

🧹 Nitpick comments (3)
controlplane/test/contracts.test.ts (3)

25-25: LGTM on adding a schema header; consider centralizing for reuse

The header constant stabilizes expectations. Consider moving this to a shared test helper (e.g., test utils) so other tests can reuse the same header and reduce drift.


25-25: Make SDL comparisons resilient and DRY

Direct string equality on multi-line SDLs is brittle. Normalize both sides once via a small helper and reuse it across assertions.

Apply this pattern:

@@
-const schemaDefinition = `schema {\n  query: Query\n}\n\n`
+const schemaDefinition = `schema {\n  query: Query\n}\n\n`
+const expectClientSchema = (actual: string | undefined, body: string) => {
+  expect(normalizeString(actual ?? '')).toBe(normalizeString(schemaDefinition + body));
+};

Example usages (apply similarly to the other assertions listed in this comment’s line ranges):

@@
-    expect(sdlResponse.clientSchema).toEqual(schemaDefinition + `type Query {
-  hello: String!
-}`);
+    expectClientSchema(sdlResponse.clientSchema, `type Query {
+  hello: String!
+}`);
@@
-    expect(sdlResponse2.clientSchema).toEqual(schemaDefinition + `type Query {\n  hello: String!\n  hi: String!\n}`);
+    expectClientSchema(sdlResponse2.clientSchema, `type Query {\n  hello: String!\n  hi: String!\n}`);

Note: also prefer multi-line template literals over embedded “\n” for readability where possible.

Also applies to: 1041-1044, 1056-1056, 1096-1096, 1109-1109, 1159-1163, 1174-1177, 1292-1296, 1308-1311, 1352-1356, 1369-1372, 1432-1435, 1449-1450


1736-1740: Client schema header in router config: good; add directive coverage to match PR goal

The client SDL now includes the schema header—nice. Given the PR intent (“print client schema with select directives”), add 1–2 targeted assertions that those directives are present in the printed client schema (where applicable) to lock in behavior.

For example, after the existing equality check:

+ expect(normalizeString(executionConfig.engineConfig!.graphqlClientSchema!))
+   .toContain('directive @tag(')

And in the “include tags” variant (where auth/scope directives are present upstream):

+ expect(normalizeString(executionConfig.engineConfig!.graphqlClientSchema!))
+   .toContain('directive @authenticated')
+ expect(normalizeString(executionConfig.engineConfig!.graphqlClientSchema!))
+   .toContain('directive @requiresScopes')

If the design is to omit unused directive definitions from the client SDL, please confirm and we’ll skip these.

Also applies to: 1841-1845, 1998-2002, 2104-2108

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d00d770 and c936ac7.

📒 Files selected for processing (1)
  • controlplane/test/contracts.test.ts (21 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-08T20:57:07.946Z
Learnt from: JivusAyrus
PR: wundergraph/cosmo#2156
File: controlplane/src/core/repositories/SubgraphRepository.ts:1746-1763
Timestamp: 2025-09-08T20:57:07.946Z
Learning: The checkSubgraphSchema.ts file already correctly implements linked subgraph functionality, using byName(linkedSubgraph.name, linkedSubgraph.namespace) to fetch target subgraphs and properly handles parse(newSchemaSDL) for schema building. The implementation doesn't need fixes for byId usage or schema parsing as it's already correct.

Applied to files:

  • controlplane/test/contracts.test.ts
⏰ 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). (7)
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: build_test
  • GitHub Check: build_push_image
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)

@Aenimus Aenimus merged commit fe41836 into main Sep 19, 2025
23 checks passed
@Aenimus Aenimus deleted the david/eng-8198-print-client-schema-with-directives branch September 19, 2025 19: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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants