feat(indexer/distributions): define distributions GraphQL schema (#37)#50
feat(indexer/distributions): define distributions GraphQL schema (#37)#50modrispath wants to merge 2 commits into
Conversation
|
@modrispath Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughThe distributions GraphQL schema now defines full batch and claim types, adds filter and pagination inputs plus connection wrappers, extends root queries for lookups and lists, and includes Vitest coverage for the new schema surface. ChangesDistributions GraphQL Schema
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
indexer/distributions/src/schema.test.ts (1)
20-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winScope type-field assertions and cover the timestamp fields.
These checks currently search the whole schema, so shared fields like
id,txHash, orcreatedAtcan pass even if they move to the wrong type. Also add assertions forDistributionBatch.createdAt,DistributionBatch.updatedAt, andClaimAction.createdAt.Example test helper
+const definitionBody = (kind: "type" | "input" | "enum", name: string) => { + const match = schemaContent.match( + new RegExp(`${kind}\\s+${name}\\s*\\{([\\s\\S]*?)\\n\\}`), + ); + expect(match).not.toBeNull(); + return match?.[1] ?? ""; +}; + test("defines DistributionBatch type aligned with database schema", () => { - expect(schemaContent).toContain("type DistributionBatch {"); - expect(schemaContent).toContain("id: ID!"); + const distributionBatch = definitionBody("type", "DistributionBatch"); + expect(distributionBatch).toContain("id: ID!"); expect(schemaContent).toContain("contractId: String!"); + expect(distributionBatch).toContain("createdAt: String!"); + expect(distributionBatch).toContain("updatedAt: String!"); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@indexer/distributions/src/schema.test.ts` around lines 20 - 47, Tighten the schema tests in schema.test.ts so each field assertion is scoped to the correct type block instead of searching the full schema content. Update the DistributionBatch and ClaimAction tests to extract or match the specific type definitions using their unique type names, then assert fields like id, txHash, and createdAt within that block only. Also add coverage for DistributionBatch.createdAt, DistributionBatch.updatedAt, and ClaimAction.createdAt to keep the schema alignment checks complete.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@indexer/distributions/schema.graphql`:
- Line 22: The Distribution schema currently exposes claims as an unbounded
list, which can let distributionBatch load every claim for a batch and skip
pagination. Update the claims field on the Distribution type in schema.graphql
to use a paginated connection shape, or remove the nested list and rely on
claimsByBatch for batch-scoped access; make sure any related resolver or type
references for claims and distributionBatch are updated to match the new
paginated API.
---
Nitpick comments:
In `@indexer/distributions/src/schema.test.ts`:
- Around line 20-47: Tighten the schema tests in schema.test.ts so each field
assertion is scoped to the correct type block instead of searching the full
schema content. Update the DistributionBatch and ClaimAction tests to extract or
match the specific type definitions using their unique type names, then assert
fields like id, txHash, and createdAt within that block only. Also add coverage
for DistributionBatch.createdAt, DistributionBatch.updatedAt, and
ClaimAction.createdAt to keep the schema alignment checks complete.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e9504122-d739-4e78-8ebf-285e25d5f48b
📒 Files selected for processing (2)
indexer/distributions/schema.graphqlindexer/distributions/src/schema.test.ts
|
Hi @modrispath Thank you for your awesome contribution, however after analyzing your implementation, there is a minor fix to be done. Kindly fix it to merge your PR asap. Also do not forget to use fundable.finance to offramp. |
|
Hi @pragmaticAweds, I've applied the requested fixes! Specifically:
All checks (�un run type-check, �un run test, �un run lint, and indexer workspace checks) pass cleanly. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@indexer/distributions/src/schema.test.ts`:
- Around line 20-24: The helper in schema.test.ts is relying on regex over raw
SDL, which can miss malformed or invalid schema content; replace this in
definitionBody with parsing/building the schema once and asserting against the
resulting AST or type map. Use the existing schemaContent-driven test setup to
locate the relevant type/input/enum definitions by name from the parsed
structure instead of matching text blocks, so syntax errors, duplicates, and
invalid fields are actually detected.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e11cb7f5-f272-4ad5-862d-2116c86c7b65
📒 Files selected for processing (2)
indexer/distributions/schema.graphqlindexer/distributions/src/schema.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- indexer/distributions/schema.graphql
| const definitionBody = (kind: "type" | "input" | "enum", name: string) => { | ||
| const match = schemaContent.match(new RegExp(`${kind}\\s+${name}\\s*\\{([\\s\\S]*?)\\n\\}`)); | ||
| expect(match).not.toBeNull(); | ||
| return match?.[1] ?? ""; | ||
| }; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Parse the SDL instead of regex-matching raw text.
This helper lets the suite pass on malformed schema text as long as the expected substrings still exist somewhere in the file. That means syntax errors, duplicate definitions, or invalid field declarations can slip through here. Please build/parse the schema once and assert on the resulting type map/AST instead of extracting blocks with regex.
Suggested direction
+import { buildSchema, isEnumType, isInputObjectType, isObjectType } from "graphql";
+
describe("distributions GraphQL schema", () => {
const schemaContent = readFileSync(schemaPath, "utf-8");
+ const schema = buildSchema(schemaContent);
-
- const definitionBody = (kind: "type" | "input" | "enum", name: string) => {
- const match = schemaContent.match(new RegExp(`${kind}\\s+${name}\\s*\\{([\\s\\S]*?)\\n\\}`));
- expect(match).not.toBeNull();
- return match?.[1] ?? "";
- };
test("defines DistributionBatch type aligned with database schema", () => {
- const body = definitionBody("type", "DistributionBatch");
- expect(body).toContain("id: ID!");
+ const type = schema.getType("DistributionBatch");
+ expect(isObjectType(type)).toBe(true);
+ expect(type?.getFields().id.type.toString()).toBe("ID!");
});🧰 Tools
🪛 ast-grep (0.44.0)
[warning] 20-20: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns.
Context: new RegExp(${kind}\\s+${name}\\s*\\{([\\s\\S]*?)\\n\\})
Note: [CWE-1333] Inefficient Regular Expression Complexity
(regexp-from-variable)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@indexer/distributions/src/schema.test.ts` around lines 20 - 24, The helper in
schema.test.ts is relying on regex over raw SDL, which can miss malformed or
invalid schema content; replace this in definitionBody with parsing/building the
schema once and asserting against the resulting AST or type map. Use the
existing schemaContent-driven test setup to locate the relevant type/input/enum
definitions by name from the parsed structure instead of matching text blocks,
so syntax errors, duplicates, and invalid fields are actually detected.
Overview
Defines the distributions domain GraphQL schema for the Soroban indexer (\indexer/distributions/schema.graphql), describing the public API shape before Apollo resolvers are implemented. This schema aligns with the database model defined in #36 and follows the conventions established in the streams domain (#33).
Closes #37
## Changes
- **Expanded \indexer/distributions/schema.graphql**:
- Added \DistributionStatus\ enum (\ACTIVE, \PAUSED, \COMPLETED, \CANCELLED).
- Defined \DistributionBatch\ type with integer-safe numeric string amounts (\ otalAmount, \claimedAmount), recipient counts, lifecycle status fields (\pausedAt, \
esumedAt), metadata (\uniqueRef, \ledgerNumber, \ xHash), and linked \claims.
- Defined \ClaimAction\ type linking claims to batches (\�atchId), storing \claimant, integer-safe \�mount, \ xHash, \ledgerNumber, and \eventTimestamp.
- Added query filter input shapes (\DistributionFilterInput, \ClaimFilterInput) and \PaginationInput.
- Added Relay-style pagination connection types (\DistributionConnection, \ClaimConnection, \PageInfo).
- Defined root \Query\ resolvers for single lookups (\distributionBatch, \claimAction) and paginated list queries (\distributionBatches, \distributionBatchesByDistributor, \claims, \claimsByClaimant, \claimsByBatch).
- Unit Tests:
- Added \indexer/distributions/src/schema.test.ts\ to assert that the GraphQL schema defines all required types, queries, inputs, connections, and status enums aligned with the database model.
## Verification
Run across workspace:
- \�un run type-check\ passed
- \�un run test\ passed
- \�un run lint\ passed
- \�un run indexer:type-check\ passed
- \�un run indexer:test\ passed
- \�un run indexer:lint\ passed
Summary by CodeRabbit