Skip to content

Refine GraphQL client API#53

Merged
leynos merged 1 commit intomainfrom
codex/implement-api-improvements-post-refactoring
Aug 3, 2025
Merged

Refine GraphQL client API#53
leynos merged 1 commit intomainfrom
codex/implement-api-improvements-post-refactoring

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 31, 2025

Summary

  • expose GraphQLClient publicly and re-export it at the crate root
  • rename GraphQlResponse to GraphQLResponse
  • provide public run_query method and use it from callers
  • export pagination helper at crate root
  • document the crate root re-exports

Closes #49


https://chatgpt.com/codex/tasks/task_e_688be4826d5483228cf042eece1ed9e4

Summary by Sourcery

Refine the GraphQL client API by exposing core types and helpers at the crate root, renaming response types, and converting the standalone query helper into a method.

New Features:

  • Expose GraphQLClient and run_query at the crate root
  • Export paginate helper and PageInfo type publicly

Enhancements:

  • Rename GraphQlResponse to GraphQLResponse and update call sites to use client.run_query
  • Make VkError enum and PageInfo struct publicly accessible

Documentation:

  • Document crate root re-exports of GraphQLClient, run_query, and pagination utilities

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 31, 2025

Reviewer's Guide

This PR refines the GraphQL client API by exposing and re-exporting the client and helpers at the crate root, renaming the response type, consolidating query execution through the client, and updating visibility for core types.

Class diagram for updated GraphQL client API

classDiagram
    class GraphQLClient {
        +new(token: &str, transcript: Option<PathBuf>) Result<GraphQLClient, io::Error>
        +with_endpoint(token: &str, endpoint: &str, transcript: Option<PathBuf>) Result<GraphQLClient, io::Error>
        +run_query(query: &str, variables: V) Result<T, VkError>
        -client: reqwest::Client
        -headers: HeaderMap
        -endpoint: String
        -transcript: Option<Mutex<File>>
    }

    class GraphQLResponse~T~ {
        data: Option<T>
        errors: Option<Vec<GraphQlError>>
    }

    class VkError {
        RepoNotFound
        RequestFailed(String)
        BadResponseSerde(String)
        // ... other variants
    }

    class PageInfo {
        +has_next_page: bool
        +end_cursor: Option<String>
    }

    GraphQLClient --> VkError
    GraphQLClient --> GraphQLResponse
    GraphQLClient --> PageInfo

    %% Note: run_query is now a public method on GraphQLClient, and GraphQLClient is public and re-exported at the crate root.
Loading

Class diagram for crate root re-exports and helpers

classDiagram
    class paginate {
        +paginate(fetch: FnMut(Option<String>) -> Fut) Result<Vec<T>, VkError>
    }

    class GraphQLClient
    class PageInfo

    %% These are now re-exported at the crate root for public use.
    paginate ..> VkError
    paginate ..> PageInfo
    GraphQLClient <.. paginate : uses
Loading

File-Level Changes

Change Details Files
Publicize and re-export GraphQLClient and helpers
  • Made GraphQLClient struct public
  • Exposed new() and with_endpoint() constructors with error docs
  • Promoted run_query_impl to a public run_query method with docs
  • Added crate-root re-exports for GraphQLClient and paginate
  • Updated design docs to describe root-level exports
src/api/mod.rs
docs/vk-design.md
Rename GraphQlResponse to GraphQLResponse
  • Renamed response struct to GraphQLResponse
  • Updated deserialization and internal references to use new name
src/api/mod.rs
Consolidate query execution through GraphQLClient
  • Removed standalone run_query helper function
  • Replaced api::run_query calls with client.run_query in main.rs and reviews.rs
  • Dropped api:: prefix on paginate usage to use root-level helper
src/api/mod.rs
src/main.rs
src/reviews.rs
Expose core types publicly
  • Changed VkError enum visibility to pub
  • Updated PageInfo struct to be public
src/main.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#49 Simplify API surface: Make the run_query_impl method on GraphQLClient public as run_query and remove the standalone free-function wrapper.
#49 Reduce import noise: Re-export GraphQLClient, run_query, and paginate at the crate root so callers can use crate::run_query instead of api::run_query.
#49 Improve naming consistency: Rename GraphQlResponse to GraphQLResponse to unify casing with GraphQLClient.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 31, 2025

Summary by CodeRabbit

  • New Features

    • Made the GraphQL client and pagination utilities publicly accessible, allowing direct use in external projects.
    • Enhanced documentation for public methods, including improved error descriptions.
  • Refactor

    • Simplified usage of the GraphQL client and pagination by enabling direct method calls and removing redundant helper functions.
    • Updated naming for consistency and clarity across the interface.
  • Documentation

    • Clarified the networking logic and updated descriptions to reflect the new public API structure.

Walkthrough

Refactor the GraphQL API module to improve consistency and usability. Make GraphQLClient and its methods public, rename GraphQlResponse to GraphQLResponse, remove the standalone run_query function, and update documentation and imports throughout the codebase to reflect these changes. Update usage sites to call methods directly.

Changes

Cohort / File(s) Change Summary
GraphQL API module refactor
src/api/mod.rs
Make GraphQLClient and its constructors public; rename GraphQlResponse to GraphQLResponse; make run_query_impl public as run_query; remove standalone run_query function; update documentation and error descriptions.
Main module API exposure and usage update
src/main.rs
Make api, VkError, and PageInfo public; re-export GraphQLClient and paginate at crate root; update all usages to call client.run_query and re-exported paginate directly.
Review utilities import and usage update
src/reviews.rs
Import GraphQLClient and paginate from crate root; update function calls to use client.run_query and direct paginate usage, removing intermediate api:: references.
Documentation update
docs/vk-design.md
Clarify networking logic documentation to reflect crate root re-exports and updated naming for pagination utility.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant GraphQLClient
    participant API

    Caller->>GraphQLClient: new(token, transcript)
    Caller->>GraphQLClient: run_query(query, variables)
    GraphQLClient->>API: Send GraphQL request
    API-->>GraphQLClient: Return response or VkError
    GraphQLClient-->>Caller: Return deserialised data or VkError

    Caller->>paginate: paginate(fetch_page_closure)
    paginate->>GraphQLClient: run_query (in closure)
    GraphQLClient-->>paginate: Return page data or VkError
    paginate-->>Caller: Return paginated results or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Simplify API surface: Make run_query_impl public as run_query and remove standalone wrapper (#49)
Reduce import noise: Re-export GraphQLClient, run_query, and paginate at crate root (#49) Only GraphQLClient and paginate are re-exported; run_query is now a method, not free.
Improve naming consistency: Rename GraphQlResponse to GraphQLResponse (#49)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs

Poem

Refactor the client, make APIs clear,
Rename the response, let casing adhere.
Imports are lighter, the noise swept away,
Methods now public, in bright Rust array.
With crate root exports, the code sings anew—
Consistent, concise, and easier to view!
🚀✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ece167b and 7f43091.

📒 Files selected for processing (4)
  • docs/vk-design.md (1 hunks)
  • src/api/mod.rs (7 hunks)
  • src/main.rs (8 hunks)
  • src/reviews.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.md

⚙️ CodeRabbit Configuration File

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
  • Code blocks should be wrapped to 120 columns.
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/vk-design.md
**/*.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • src/reviews.rs
  • src/main.rs
  • src/api/mod.rs
🧬 Code Graph Analysis (2)
src/reviews.rs (1)
src/api/mod.rs (1)
  • paginate (210-226)
src/main.rs (1)
src/api/mod.rs (1)
  • paginate (210-226)
🪛 LanguageTool
docs/vk-design.md

[misspelling] ~48-~48: This word is normally spelled with a hyphen.
Context: ...c/api/mod.rs](../src/api/mod.rs) and is re- exported at the crate root. The module exposes t...

(EN_COMPOUNDS_RE_EXPORTED)

🔇 Additional comments (16)
docs/vk-design.md (1)

48-51: Documentation accurately reflects the API refactoring.

The updates correctly document that the api module is re-exported at the crate root, exposing GraphQLClient with its run_query method and the paginate helper. This aligns with the refactoring objectives.

src/reviews.rs (3)

13-13: Import consolidation correctly reflects the re-exported API.

The direct import of GraphQLClient and paginate from the crate root removes unnecessary module path noise and aligns with the refactoring objectives.


75-85: Method call correctly uses the client instance directly.

The transition from api::run_query to calling run_query directly on the GraphQLClient instance follows the new API pattern where the client's methods are used directly rather than through standalone functions.


95-95: Pagination call correctly uses the re-exported function.

The direct call to paginate instead of api::paginate follows the new pattern where core utilities are re-exported at the crate root for easier access.

src/main.rs (5)

8-8: Module visibility correctly made public.

Making the api module public enables external access to its contents while the re-exports provide a cleaner import path.


12-12: Re-exports correctly expose key API components.

The re-export of GraphQLClient and paginate at the crate root provides the simplified import surface described in the PR objectives, reducing import noise for consumers.


73-73: Supporting types correctly made public.

Making VkError and PageInfo public enables external code to handle errors and work with pagination data from the GraphQL client.

Also applies to: 190-190


280-282: Internal usage correctly demonstrates the new API pattern.

The transition from api::run_query to calling run_query directly on GraphQLClient instances shows the improved API in action and validates the refactoring approach.

Also applies to: 301-310, 320-330


340-340: Pagination calls correctly use the re-exported function.

The direct calls to paginate instead of api::paginate demonstrate the simplified usage pattern enabled by the crate root re-exports.

Also applies to: 356-356

src/api/mod.rs (7)

33-33: Type name correctly unified for consistency.

Renaming GraphQlResponse to GraphQLResponse creates consistent capitalisation with GraphQLClient, improving the API's naming coherence.


74-74: Client visibility correctly made public.

Changing GraphQLClient from pub(crate) to pub enables external access whilst the re-export at the crate root provides a clean import path.


86-89: Constructor documentation correctly follows Rust conventions.

The added # Errors sections properly document when std::io::Error is returned, following standard Rust documentation patterns for fallible functions.

Also applies to: 103-106


90-90: Constructor methods correctly made public.

Making the new and with_endpoint methods public enables external instantiation of the GraphQLClient, supporting the API's public usage.

Also applies to: 107-107


127-133: Query method correctly promoted to public API.

The transition from run_query_impl to public run_query eliminates the need for a wrapper function whilst adding proper documentation. The error documentation correctly specifies when VkError is returned.


171-171: Response type correctly updated to match rename.

The usage of GraphQLResponse instead of GraphQlResponse maintains consistency with the type rename.


206-209: Pagination documentation correctly documents error propagation.

The added # Errors section properly documents that VkError from the fetch closure is propagated, following Rust documentation conventions.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/implement-api-improvements-post-refactoring

🪧 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.
    • 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 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 docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for 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 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
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `docs/vk-design.md:48` </location>
<code_context>
-Networking logic resides in [src/api/mod.rs](../src/api/mod.rs). It exposes the
-`GraphQLClient` alongside the `run_query` helper and pagination utilities used
-throughout the application.
+Networking logic resides in [src/api/mod.rs](../src/api/mod.rs) and is re-
+exported at the crate root. The module exposes the `GraphQLClient` with a
+`run_query` method, along with the `paginate` helper used throughout the
</code_context>

<issue_to_address>
This paragraph line exceeds 80 columns and should be wrapped accordingly.

Please ensure that all paragraph lines are wrapped to a maximum of 80 columns for consistency and readability, as per the style guide.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread docs/vk-design.md
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 3, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos leynos merged commit 42152e3 into main Aug 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor GraphQL API module for better consistency and usability

1 participant