Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Fix backend query[PFT-2494]#100

Merged
sudeepb02 merged 3 commits intodevelopfrom
fix/query
Apr 4, 2025
Merged

Fix backend query[PFT-2494]#100
sudeepb02 merged 3 commits intodevelopfrom
fix/query

Conversation

@iamamitkumar0512
Copy link
Contributor

@iamamitkumar0512 iamamitkumar0512 commented Apr 4, 2025

Summary by CodeRabbit

  • Chores
    • Updated the SDK version to 2.2.12.
  • Refactor
    • Improved account information mapping for enhanced data consistency.
  • New Features
    • Enhanced position data retrieval so that only accounts with active or valid historical positions are displayed, ensuring more focused and relevant results.

@iamamitkumar0512 iamamitkumar0512 self-assigned this Apr 4, 2025
@notion-workspace
Copy link

Fix sdk query

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

This pull request updates the package version, modifies a property assignment within the subgraph mapper, adds a logging statement in the positions module, refines several GraphQL queries by removing an unused field and adding filters, and updates test cases for open and closed positions. These changes adjust how data is sourced and validated while extending test coverage.

Changes

File(s) Change Summary
package.json Updated version from "2.2.11" to "2.2.12".
src/common/subgraphMapper.ts Changed property assignment in mapResponseToSnxAccount from using response?.wallet to response?.owner.
src/subgraph/positions/index.ts Added a logging statement (console.log('subgraphresponse', subgraphResponse)) in the getAllOpenPositionsWithTime function.
src/subgraph/positions/subgraphQueries.ts Removed positionCollateral from multiple queries and added filters (openPositionCount_gt: 0 and totalPositionsCount_gt: 0) to refine data retrieval.
test/subgraph-tests/position.test.ts Modified an existing test case by removing .only and added two new test cases for fetching open and closed positions within specified timeframes (one of which uses .only).

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant OP as OpenPositions Function
    participant Q as Query Module
    participant S as Subgraph
    T->>OP: getAllOpenPositionsWithTime(startTime, endTime)
    OP->>Q: Build query with openPositionCount_gt: 0
    Q->>S: Execute query
    S-->>Q: Return subgraphResponse
    Q-->>OP: Return subgraphResponse
    OP->>Console: Log subgraphResponse
    OP-->>T: Return open positions
Loading
sequenceDiagram
    participant T as Test Suite
    participant CP as ClosedPositions Function
    participant Q as Query Module
    participant S as Subgraph
    T->>CP: getAllPositionHistoryWithTime(startTime, endTime)
    CP->>Q: Build query with totalPositionsCount_gt: 0
    Q->>S: Execute query
    S-->>Q: Return subgraphResponse
    Q-->>CP: Return subgraphResponse
    CP-->>T: Return closed positions
Loading

Poem

I’m a rabbit hopping through the code plain,
Tweaking queries and tests with a joyful refrain.
I log each step with a happy little cheer,
Shifting from wallet to owner, crystal clear!
Versions updated, bugs hop away 🐇
In this code garden, I celebrate a bright new day!
🌼🐰

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @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

Documentation and Community

  • 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
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: 2

🧹 Nitpick comments (2)
src/subgraph/positions/index.ts (1)

207-207: Consider removing the console.log statement.

This logging statement appears to be added for debugging purposes. While useful during development, console logs should generally be removed from production code as they can clutter logs and potentially impact performance.

-    console.log('subgraphresponse', subgraphResponse);

Alternatively, consider using a proper logging framework with configurable log levels if this information is needed for troubleshooting in production environments.

test/subgraph-tests/position.test.ts (1)

44-44: Remove or comment out console.log statements.

Console log statements in tests can clutter test output. Consider removing them or commenting them out before merging to production.

-    console.log('Position data:::', positionData);
+    // console.log('Position data:::', positionData);

Also applies to: 52-52

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f13c0d4 and 22c4218.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • package.json (1 hunks)
  • src/common/subgraphMapper.ts (1 hunks)
  • src/subgraph/positions/index.ts (1 hunks)
  • src/subgraph/positions/subgraphQueries.ts (2 hunks)
  • test/subgraph-tests/position.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
test/subgraph-tests/position.test.ts (1)
test/index.ts (1)
  • getParifiSdkInstanceForTesting (5-33)
🪛 Biome (1.9.4)
test/subgraph-tests/position.test.ts

[error] 47-47: Don't focus the test.

The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.

(lint/suspicious/noFocusedTests)

🪛 GitHub Actions: Test contracts sdk
test/subgraph-tests/position.test.ts

[error] 34-34: Error fetching positions: ClientError: GraphQL Error (Code: 403): Access denied.

🔇 Additional comments (7)
package.json (1)

3-3: Version bump looks appropriate.

The increment from 2.2.11 to 2.2.12 follows semantic versioning principles, indicating a patch release with backward-compatible bug fixes. This aligns with the changes being made across the other files.

src/common/subgraphMapper.ts (1)

45-45: Good fix for the owner property mapping.

The change from accessing wallet to owner correctly aligns with the GraphQL schema structure seen in the queries. This fixes a potential bug where the owner information wasn't being properly mapped from the response data.

Verify that this change has been validated in your tests to ensure the property is correctly accessed in all scenarios.

src/subgraph/positions/subgraphQueries.ts (2)

404-407: Good performance improvement for open positions query.

Adding the openPositionCount_gt:0 filter to the query is an excellent optimization. This will filter out accounts with no open positions at the database level rather than fetching unnecessary data, resulting in:

  • Reduced network payload
  • Faster query execution
  • Less client-side processing

472-472: Good optimization for position history query.

Adding the totalPositionsCount_gt :0 filter ensures we only fetch accounts that have at least one position in their history. This optimization will:

  • Improve query performance
  • Reduce unnecessary data transfer
  • Speed up response times
test/subgraph-tests/position.test.ts (3)

41-42: Verify the timeframe values are correct.

The timeframe values (Unix timestamps) deserve validation:

  • Open positions: startTime=1735689600 (Jan 1, 2025), endTime=2035689600 (Jan 27, 2034)
  • Closed positions: startTime=1743710952 (May 1, 2025), endTime=1743763152 (May 2, 2025)

These timestamps are in the future. Please confirm they're intentional for testing purposes.

Also applies to: 49-50


39-46: LGTM - Test for open positions.

The test for retrieving open positions within a specific timeframe looks good. It properly tests the getAllOpenPositionsWithTime method with appropriate expectations.


31-38: LGTM - Removing .only from existing test.

Good change to remove the .only modifier from this test, allowing all tests to run.

🧰 Tools
🪛 GitHub Actions: Test contracts sdk

[error] 34-34: Error fetching positions: ClientError: GraphQL Error (Code: 403): Access denied.

@sudeepb02 sudeepb02 merged commit 4d61b1a into develop Apr 4, 2025
2 checks passed
@sudeepb02 sudeepb02 deleted the fix/query branch April 4, 2025 14:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants