Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gql user query #355

Closed
wants to merge 3 commits into from
Closed

feat: add gql user query #355

wants to merge 3 commits into from

Conversation

ruslan-sh-r
Copy link
Contributor

@ruslan-sh-r ruslan-sh-r commented May 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced user-related query functionality in the GraphQL module, enhancing user data handling.
  • Bug Fixes

    • No bug fixes in this release.
  • Chores

    • Upgraded cosmjs dependency.
    • Updated the TypeScript SDK version to 4.3.2.
  • Tests

    • Added new tests for user-related functionality in the heart-monitor module.

cgilbe27 and others added 3 commits May 16, 2024 10:17
### [4.3.2](v4.3.1...v4.3.2) (2024-05-16)

### Miscellaneous Chores

* upgrading cosmjs ([#352](#352)) ([32739a7](32739a7))

 [skip ci]
@ruslan-sh-r ruslan-sh-r changed the title ffeat: add gql user query feat: add gql user query May 28, 2024
Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

In version 4.3.2 of the ts-sdk repository, the primary change is the upgrade of cosmjs. Additionally, new user-related GraphQL functionalities were introduced, including new interfaces, functions, and test cases. These enhancements improve the GraphQL module's ability to handle user queries.

Changes

File Path Change Summary
CHANGELOG.md Documented the upgrade of cosmjs as part of miscellaneous chores.
package.json Updated version from "4.3.1" to "4.3.2".
src/gql/heart-monitor/heart-monitor.test.ts Added GQLQueryGqlUserArgs import, testUser function, and a test case for user function.
src/gql/heart-monitor/heart-monitor.ts Added user function to IHeartMonitor interface and implemented it in HeartMonitor class.
src/gql/query/index.ts Reordered export statements.
src/gql/query/users.ts Added new interfaces (GqlOutUser, GqlOutUsers), userQueryString, user functions, and modified usersQueryString.

In code's vast land, where changes bloom,
A new version brings a brighter room.
With queries for users, refined and clear,
The heart of data draws ever near.
So let us celebrate, in bytes and cheer,
For progress made, we hold dear.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@ruslan-sh-r ruslan-sh-r deleted the feat/gql-user branch May 28, 2024 17:33
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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5990369 and 10d9cf7.
Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • package.json (1 hunks)
  • src/gql/heart-monitor/heart-monitor.test.ts (2 hunks)
  • src/gql/heart-monitor/heart-monitor.ts (3 hunks)
  • src/gql/query/index.ts (1 hunks)
  • src/gql/query/users.ts (2 hunks)
Files skipped from review due to trivial changes (3)
  • CHANGELOG.md
  • package.json
  • src/gql/query/index.ts
Additional Context Used
Biome (8)
src/gql/heart-monitor/heart-monitor.test.ts (4)

97-101: Prefer for...of instead of forEach.


98-100: Prefer for...of instead of forEach.


996-998: Prefer for...of instead of forEach.


1-94: Some named imports are only used as types.

src/gql/heart-monitor/heart-monitor.ts (3)

106-106: void is not valid as a constituent in a union type


1-2: Some named imports are only used as types.


2-101: Some named imports are only used as types.

src/gql/query/users.ts (1)

1-11: Some named imports are only used as types.

Additional comments not posted (6)
src/gql/query/users.ts (3)

13-15: The GqlOutUser interface is correctly defined and aligns with the GraphQL schema expectations.


20-31: The userQueryString function is well-implemented. It correctly constructs a GraphQL query string based on the provided arguments and fields.


10-10: Ensure that GQLQueryGqlUserArgs is used appropriately throughout the file since it's a new import.

Verification successful

The GQLQueryGqlUserArgs type is used appropriately in the src/gql/query/users.ts file and other relevant files, such as src/gql/heart-monitor/heart-monitor.ts and its corresponding test file. This confirms that the type is integrated correctly across the project.

  • src/gql/query/users.ts: Lines 10, 11, 12
  • src/gql/heart-monitor/heart-monitor.ts: Lines 10, 11, 12
  • src/gql/heart-monitor/heart-monitor.test.ts: Lines 10, 11
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `GQLQueryGqlUserArgs` across the project.

# Test: Search for the usage of `GQLQueryGqlUserArgs`. Expect: Usage in relevant files.
rg --type typescript $'GQLQueryGqlUserArgs'

Length of output: 77



Script:

#!/bin/bash
# Description: Verify the usage of `GQLQueryGqlUserArgs` across the project.

# Test: Search for the usage of `GQLQueryGqlUserArgs`. Expect: Usage in relevant files.
rg --type ts 'GQLQueryGqlUserArgs'

Length of output: 615

src/gql/heart-monitor/heart-monitor.ts (2)

226-229: The user function added to the IHeartMonitor interface is correctly typed and promises to return a GqlOutUser. This aligns with the GraphQL schema and TypeScript best practices.


372-373: The implementation of the user function in the HeartMonitor class correctly delegates to the standalone user function, ensuring separation of concerns and reusability.

src/gql/heart-monitor/heart-monitor.test.ts (1)

1001-1013: The test case for the user function is comprehensive, covering various fields and ensuring they are present. This helps in maintaining robustness in the GraphQL API's response structure.

Comment on lines +50 to +56
export const user = async (
args: GQLQueryGqlUserArgs,
endpt: string,
fields: DeepPartial<GQLUser>
): Promise<GqlOutUser> =>
doGqlQuery(userQueryString(args, false, fields), endpt)

Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The doGqlQuery function implementation does not include explicit error handling. It performs a fetch request and directly returns the cleaned response. To ensure robust error handling, consider adding try-catch blocks and handling potential errors from the fetch request.

  • Location: src/gql/utils/consts.ts
Analysis chain

The user function is correctly implemented to perform a GraphQL query using the userQueryString. Ensure that error handling is robust in the doGqlQuery function.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the error handling in `doGqlQuery` function.

# Test: Search for the implementation of `doGqlQuery`. Expect: Proper error handling.
rg --type typescript $'doGqlQuery'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify the error handling in `doGqlQuery` function.

# Test: Search for the implementation of `doGqlQuery`. Expect: Proper error handling.
rg --type ts 'doGqlQuery'

Length of output: 2565



Script:

#!/bin/bash
# Description: Extract the implementation of `doGqlQuery` function to verify error handling.

# Extract the implementation of `doGqlQuery` from `src/gql/utils/consts.ts`.
rg --type ts --context 10 'export const doGqlQuery' src/gql/utils/consts.ts

Length of output: 675

Comment on lines +991 to +999
const testUser = async (args: GQLQueryGqlUserArgs, fields: GQLUser) => {
const resp = await heartMonitor.user(args, fields)
expect(resp).toHaveProperty("user")

const fieldsToCheck = ["address", "balances", "created_block", "is_blocked"]
fieldsToCheck.forEach((field: string) => {
expect(resp.user).toHaveProperty(field)
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The testUser function is well-implemented, checking for expected properties on the user object. Consider using a for...of loop for better readability and performance in future iterations.

- fieldsToCheck.forEach((field: string) => {
-   expect(resp.user).toHaveProperty(field)
- })
+ for (const field of fieldsToCheck) {
+   expect(resp.user).toHaveProperty(field)
+ }

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.

Suggested change
const testUser = async (args: GQLQueryGqlUserArgs, fields: GQLUser) => {
const resp = await heartMonitor.user(args, fields)
expect(resp).toHaveProperty("user")
const fieldsToCheck = ["address", "balances", "created_block", "is_blocked"]
fieldsToCheck.forEach((field: string) => {
expect(resp.user).toHaveProperty(field)
})
}
const testUser = async (args: GQLQueryGqlUserArgs, fields: GQLUser) => {
const resp = await heartMonitor.user(args, fields)
expect(resp).toHaveProperty("user")
const fieldsToCheck = ["address", "balances", "created_block", "is_blocked"]
for (const field of fieldsToCheck) {
expect(resp.user).toHaveProperty(field)
}
}

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.

3 participants