Skip to content

Add support for descriptions on entities, fields, and relationships#1181

Open
DZakh wants to merge 3 commits intomainfrom
claude/fix-issue-305-dtiX3
Open

Add support for descriptions on entities, fields, and relationships#1181
DZakh wants to merge 3 commits intomainfrom
claude/fix-issue-305-dtiX3

Conversation

@DZakh
Copy link
Copy Markdown
Member

@DZakh DZakh commented May 4, 2026

Summary

This PR adds support for GraphQL descriptions on entities, fields, and relationships, enabling them to be exposed through Hasura's GraphQL introspection API. Descriptions are parsed from the schema definition and propagated through the entire configuration pipeline to Hasura.

Key Changes

  • Schema Parsing: Extended the GraphQL schema parser to extract descriptions from entity types, fields, and enums

    • Added description field to Entity, Field, and GraphQLEnum structs in the Rust config parser
    • Descriptions are preserved through the schema parsing pipeline
  • Configuration Propagation: Updated the configuration system to carry descriptions through all layers

    • Added description fields to Table, field, and derivedFromField types in ReScript
    • Updated JSON schema validation to accept optional description fields
  • Hasura Integration: Enhanced the Hasura table tracking to include descriptions

    • Modified trackTables function to accept trackTableConfig objects containing table descriptions and column descriptions
    • Updated createEntityRelationship to support relationship comments
    • Descriptions are sent to Hasura as table comments, column comments, and relationship comments
  • Test Coverage: Added comprehensive tests

    • E2E test verifying descriptions appear in GraphQL introspection
    • Unit test confirming descriptions are correctly extracted from schema definitions
    • Config parsing test validating descriptions flow through the configuration system

Implementation Details

  • Descriptions are optional throughout the system (using Option<String> in ReScript and Option<String> in Rust)
  • The implementation distinguishes between GraphQL comments (#) which are ignored, and descriptions (quoted strings) which are preserved
  • Descriptions on derived fields and relationships are properly propagated to Hasura relationship metadata
  • Column descriptions are built from field descriptions in the entity configuration

https://claude.ai/code/session_01P4pVR6WbWLk7yGX9bvqnqk

Summary by CodeRabbit

  • New Features

    • Support for GraphQL type and field descriptions, preserved across config, codegen, and runtime.
    • Descriptions are emitted in public config JSON and propagated into generated templates and DB/table metadata.
    • Table/column comments are now carried when tracking tables so schema comments show up where supported.
  • Tests

    • Added unit and E2E tests validating description extraction and end-to-end propagation.

claude added 2 commits May 4, 2026 08:56
Issue #305: extract entity, field, derivedFrom and enum descriptions
from schema.graphql, plumb them through the public config JSON into
Table.field/derivedFromField/table, and apply them as Hasura table
comments, column comments and relationship comments via pg_track_tables
and pg_create_*_relationship.

https://claude.ai/code/session_01P4pVR6WbWLk7yGX9bvqnqk
Adds string descriptions on every supported construct in the e2e_test
schema (entity, regular fields, indexed fields, derivedFrom relationship,
and a new Account entity) plus a `#` comment to confirm comments are
ignored. New e2e test pulls the full introspected schema from Hasura,
filters to the user-defined entity types, and snapshots their names
and descriptions to lock in end-to-end coverage.

https://claude.ai/code/session_01P4pVR6WbWLk7yGX9bvqnqk
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da38f630-1650-45ba-b54d-9d68b38cd3ed

📥 Commits

Reviewing files that changed from the base of the PR and between fb450a8 and fefba02.

📒 Files selected for processing (1)
  • packages/e2e-tests/src/e2e/e2e.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/e2e-tests/src/e2e/e2e.test.ts

📝 Walkthrough

Walkthrough

The PR threads optional description metadata from GraphQL schema into CLI config types, public JSON, templating outputs, ReScript config/table models, and Hasura tracking calls, and adds tests and schema fixtures to validate extraction and exposure via introspection.

Changes

Description Metadata Threading

Layer / File(s) Summary
Data Shape
packages/envio/src/db/Table.res, packages/cli/src/config_parsing/entity_parsing.rs, packages/cli/src/config_parsing/field_types.rs, packages/cli/src/hbs_templating/codegen_templates.rs
Added optional description fields to table, field, derivedFromField, GraphQLEnum, Entity, Field, and DerivedFieldTemplate types and constructors.
Schema Extraction
packages/cli/src/config_parsing/entity_parsing.rs
Parser extracts GraphQL description from enums, objects, and fields (EnumType.description, ObjectType.description, ObjField.description) and assigns them to GraphQLEnum, Entity, and Field.
Template / Codegen Wiring
packages/cli/src/hbs_templating/contract_import_templates.rs, packages/cli/src/hbs_templating/codegen_templates.rs
Ensure constructed Field includes description (set to None for Params) and propagate description into DerivedFieldTemplate.
Public Config Serialization
packages/cli/src/config_parsing/public_config_json.rs
EntityJson, PropertyJson, DerivedFieldJson gain description: Option<String> and SystemConfig::to_public_config_json populates those fields from source descriptors.
ReScript Config Parsing
packages/envio/src/Config.res, scenarios/test_codegen/test/Config_test.res
JSON schema validation accepts optional "description" for entities, properties, and derived fields; parsing forwards descriptions into Table.mkField, Table.mkDerivedFromField, and Table.mkTable. Unit test asserts parsing preserves descriptions.
Table / Storage Wiring
packages/envio/src/db/Table.res, packages/envio/src/PgStorage.res
mkField, mkDerivedFromField, mkTable accept optional ~description=?; onNewTables maps table names to trackTableConfig objects before calling Hasura.
Hasura Integration
packages/envio/src/Hasura.res
Introduced trackTableConfig type; trackTables now accepts tableConfigs (including table comment and column_config with per-column comments); createEntityRelationship accepts optional comment; trackDatabase builds and passes configs derived from entity/field descriptions.
Schema & E2E
scenarios/e2e_test/schema.graphql, packages/e2e-tests/src/e2e/e2e.test.ts
GraphQL schema augmented with string descriptions for Transfer fields and new Account type; new E2E test introspects types/fields and asserts descriptions are exposed.

Sequence Diagram

sequenceDiagram
    participant Schema as GraphQL Schema
    participant Parser as CLI Parser
    participant PublicJSON as Public Config JSON
    participant ReScript as ReScript Config
    participant Hasura as Hasura API

    Schema->>Parser: Read type and field descriptions
    Parser->>PublicJSON: Serialize EntityJson/PropertyJson/DerivedFieldJson (with descriptions)
    PublicJSON->>ReScript: Public config parsed (description fields accepted)
    ReScript->>Hasura: Build trackTableConfig (table comment + column_config)
    Hasura->>Hasura: Track tables + set table/column comments
    Hasura->>Schema: Expose comments via introspection
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Aggregate queries configuration #571: Modifies Hasura tracking/relationship functions; related to this PR's changes in Hasura.res and trackTables/trackDatabase.
  • ClickHouse Sink #823: Touches config parsing types in entity_parsing.rs and field_types.rs; related to the added description fields in those structs.
  • Just clean up, no changes #609: Alters Table.res signatures; related to this PR's addition of optional description params on mkTable/mkField.

Suggested reviewers

  • JonoPrest
  • moose-code

"🐰
I nibble strings of schema lore,
I carry notes from field to core,
A whisper pinned as table comment,
From GraphQL text to server's font,
Hooray — descriptions hop across the floor!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature being added: support for descriptions on entities, fields, and relationships across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-issue-305-dtiX3

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
Review rate limit: 5/8 reviews remaining, refill in 19 minutes and 7 seconds.

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

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.

🧹 Nitpick comments (1)
packages/e2e-tests/src/e2e/e2e.test.ts (1)

138-233: ⚡ Quick win

Cover the other description paths this PR adds.

This snapshot proves table/column comments and the @derivedFrom array relationship, but packages/envio/src/Hasura.res also wires field.description into object relationships, and the PR scope includes enum descriptions too. A regression in either path would still pass here. Add one linked-entity field and one described enum to the scenario, then include them in this snapshot as well.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/e2e-tests/src/e2e/e2e.test.ts` around lines 138 - 233, The test
"should expose schema descriptions via GraphQL introspection" currently only
asserts table/column comments and a `@derivedFrom` relationship; modify the test
to also cover an object-relationship field and a described enum added by the PR:
update the userTypeNames set and/or include the enum type name so the
introspected result includes the enum, add the linked-entity field name (the
object relationship wired via field.description in Hasura.res) to the fields
mapping in the userTypes construction so it appears in the snapshot, and then
update the inline snapshot in this test to include the new relationship field
(with its description) and the described enum (with its description and enum
values) so both paths are asserted. Ensure you reference the test block by its
title and update the userTypes / snapshot construction accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/e2e-tests/src/e2e/e2e.test.ts`:
- Around line 138-233: The test "should expose schema descriptions via GraphQL
introspection" currently only asserts table/column comments and a `@derivedFrom`
relationship; modify the test to also cover an object-relationship field and a
described enum added by the PR: update the userTypeNames set and/or include the
enum type name so the introspected result includes the enum, add the
linked-entity field name (the object relationship wired via field.description in
Hasura.res) to the fields mapping in the userTypes construction so it appears in
the snapshot, and then update the inline snapshot in this test to include the
new relationship field (with its description) and the described enum (with its
description and enum values) so both paths are asserted. Ensure you reference
the test block by its title and update the userTypes / snapshot construction
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a58e207b-247f-4134-bf27-14669cc3209b

📥 Commits

Reviewing files that changed from the base of the PR and between 1f307e5 and fb450a8.

📒 Files selected for processing (12)
  • packages/cli/src/config_parsing/entity_parsing.rs
  • packages/cli/src/config_parsing/field_types.rs
  • packages/cli/src/config_parsing/public_config_json.rs
  • packages/cli/src/hbs_templating/codegen_templates.rs
  • packages/cli/src/hbs_templating/contract_import_templates.rs
  • packages/e2e-tests/src/e2e/e2e.test.ts
  • packages/envio/src/Config.res
  • packages/envio/src/Hasura.res
  • packages/envio/src/PgStorage.res
  • packages/envio/src/db/Table.res
  • scenarios/e2e_test/schema.graphql
  • scenarios/test_codegen/test/Config_test.res

Hasura overrides the relationship `comment` we set via
pg_create_array_relationship with hardcoded defaults ("An array
relationship" / "An aggregate relationship") in GraphQL introspection.
Our schema-level description still lands in Hasura's metadata API but
isn't visible to introspection, so the snapshot must capture Hasura's
defaults. Also accounts for the auto-generated `outgoing_aggregate`
sibling that Hasura adds when the related table allows aggregations.

https://claude.ai/code/session_01P4pVR6WbWLk7yGX9bvqnqk
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.

2 participants