Skip to content

refactor(thegraph)!: simpler getTheGraphClient interface #1621

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

alexandre-abrioux
Copy link
Member

@alexandre-abrioux alexandre-abrioux commented May 13, 2025

Context

  1. I forgot to export defaultGetTheGraphClientUrl at the package level in feat(payment-detection): option to use TheGraph Network with API key #1610
  2. The naming for both methods defaultGetTheGraphClient and defaultGetTheGraphClientUrl is a bit out of place when looking at the convention we have in other packages (see getDefaultIpfsUrl, getDefaultIpfsTimeout, getDefaultEthereumProvider, getDefaultProvider, getDefaultEthereumBlockConfirmations, getDefaultCurrencyVersion, CurrencyManager.getDefault, etc.)
  3. The methods defaultGetTheGraphClient and getTheGraphClient are redundant:
    • defaultGetTheGraphClient accepts a network and options
    • getTheGraphClient accepts a network, an URL, and the same options
    • options already contains connection parameters (e.g. theGraphExplorerApiKey), so it could very well host a new optional "URL" parameter. This would allow merging both methods into one.

Changes

I added the missing export and renamed/merged methods listed above. Conclusion: interface for TheGraph clients is simpler/less confusing.

Note

This is a breaking change as the interface for getTheGraphClient changes slightly. Regarding the other methods:

  • defaultGetTheGraphClient was not exported at the package level, OK
  • defaultGetTheGraphClientUrl was not exported at the package level, OK

Summary by CodeRabbit

  • New Features

    • Added support for specifying a custom subgraph URL when connecting to The Graph, providing greater flexibility for advanced users.
  • Documentation

    • Improved and clarified documentation with corrected terminology, consistent formatting, and updated code block language tags.
  • Refactor

    • Simplified and centralized the logic for resolving subgraph URLs, making client configuration more streamlined.

Copy link
Contributor

coderabbitai bot commented May 13, 2025

## Walkthrough

The changes centralize and extend the logic for determining TheGraph subgraph client URLs by introducing a new `getTheGraphClientUrl` function, allowing an explicit `url` override in options. Related imports, exports, and test cases were updated for consistency. Documentation was also revised for minor textual and formatting improvements.

## Changes

| File(s)                                                                                   | Change Summary                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `packages/payment-detection/README.md`                                                    | Updated textual and formatting issues: capitalized "TypeScript," corrected "subgraphes schema" to "subgraphs schema," and standardized shell code block tags to `sh`. No functional or code example changes.                                                                                                                                                                                                                                                                                                                                                           |
| `packages/payment-detection/src/index.ts`                                                 | Added `getTheGraphClientUrl` to imports and exports from `./thegraph`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `packages/payment-detection/src/payment-network-factory.ts`                               | Changed import from `defaultGetTheGraphClient` to `getTheGraphClient` and updated usage accordingly. No logic changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `packages/payment-detection/src/thegraph/client.ts`                                       | - Added optional `url` property to `TheGraphClientOptions`. <br> - Renamed and replaced `defaultGetTheGraphClientUrl` with `getTheGraphClientUrl` that prioritizes `url` option. <br> - Changed `getTheGraphClient` signature to accept only network and options, deriving URL internally. <br> - Removed `defaultGetTheGraphClient`. <br> - Centralized and simplified client creation and URL resolution.                                                                                                                               |
| `packages/payment-detection/test/thegraph/client.test.ts`                                 | Replaced all references to `defaultGetTheGraphClientUrl` with `getTheGraphClientUrl` in imports and test cases. Added a new test verifying that an explicitly passed URL option is returned directly.                                                                                                                                                                                                                                                                                                                                                                     |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Caller
    participant PaymentNetworkFactory
    participant TheGraphClient
    participant getTheGraphClientUrl

    Caller->>PaymentNetworkFactory: buildOptions()
    PaymentNetworkFactory->>TheGraphClient: getTheGraphClient(network, options)
    TheGraphClient->>getTheGraphClientUrl: (network, options)
    getTheGraphClientUrl-->>TheGraphClient: subgraph URL (custom or derived)
    TheGraphClient-->>PaymentNetworkFactory: TheGraphClient instance
    PaymentNetworkFactory-->>Caller: buildOptions result

Possibly related PRs

  • RequestNetwork/requestNetwork#1449: Refactored and extended client creation logic, overlapping with and now superseded by this PR's changes to client URL resolution and function removal.
  • RequestNetwork/requestNetwork#1610: Introduced the defaultGetTheGraphClientUrl function and API key support, which is now replaced and extended by the new getTheGraphClientUrl and url option logic.

Suggested reviewers

  • kevindavee
  • leoslr
  • rodrigopavezi

<!-- walkthrough_end -->

<!-- announcements_start -->

> [!NOTE]
> <details>
> <summary>⚡️ AI Code Reviews for VS Code, Cursor, Windsurf</summary>
> 
> CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
> Learn more [here](http://coderabbit.ai/ide).
> 
> </details>

---

> [!NOTE]
> <details>
> <summary>⚡️ Faster reviews with caching</summary>
> 
> CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure `Review - Disable Cache` at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the `Data Retention` setting under your Organization Settings.
> Enjoy the performance boost—your workflow just got faster.
> 
> </details>

<!-- announcements_end -->

---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Lite**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between c47799b3ab7b70a5d180b48ab6732cd33c3e2981 and dd61160e7fb1df7d43fa6d4faef63e7a9db9b35d.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `packages/payment-detection/src/index.ts` (2 hunks)
* `packages/payment-detection/src/thegraph/client.ts` (3 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary>

* packages/payment-detection/src/index.ts
* packages/payment-detection/src/thegraph/client.ts

</details>

</details>
<!-- internal state start -->


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41RyfCdMgOx3q2I1JAkBxGJkKlASDOqXTGlCICm2IMjM6m6jpyk2U3tkgFOyUn8D4Et2t1t3TWfSII8xVxHHIPczWXi0MJoL82S0C0OTrVOUDhqx3UHmLmrQjijkrkIErJiEThnibjQBbgZPbk7hzhUDUF7kLgHgMF3NPPUAAH1uREA3ywxWgYJaA3z/0GVg5nzQ5IAABWc4WgAAZgEAYHOAABYBBEKAAOeChMEgBC5CgAdlEDrGQqgvgoAE4sLCKGBaBsKEwBBkLkKbgi5QKyKGAsK0AoLTgoLLg0BzhkKGACL4xkLRBLg6wlB4wwLaBzhCKuL4x4wSBCLLg+LmL+5DAXz4KsKSLCKBAoKVAsKBAsL4w0ARLThkL4wkLkKVBzgsK2KyKoKoLuKSBLhxLaKnzdzbJzhTgLgpKsKEgBBThaAEgsLaB4KoKkhIL4Kkg6xzgoKSAmLCLaABA1KoKRKFKh4oBXzcAPy3xvyU9Mo6A3zw4FKgA= -->

<!-- internal state end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=RequestNetwork/requestNetwork&utm_content=1621):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `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 explain this code block.`
  -	`@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 explain its main purpose.`
  - `@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.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

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 sequence diagram` to generate a sequence diagram of the changes in this 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.

### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@@ -57,6 +62,7 @@ export {
initPaymentDetectionApiKeys,
getDefaultProvider,
getTheGraphClient,
getTheGraphClientUrl,
Copy link
Member Author

@alexandre-abrioux alexandre-abrioux May 13, 2025

Choose a reason for hiding this comment

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

Fixed: the export was missing at the package level

@alexandre-abrioux alexandre-abrioux changed the title refactor!(thegraph): simplify getTheGraphClient refactor(thegraph)!: simplify getTheGraphClient May 13, 2025
@alexandre-abrioux alexandre-abrioux changed the title refactor(thegraph)!: simplify getTheGraphClient refactor(thegraph)!: simpler getTheGraphClient interface May 13, 2025
@alexandre-abrioux alexandre-abrioux marked this pull request as ready for review May 13, 2025 23:26
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