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

Fix multiple Apollo clients issue #319

Merged
merged 2 commits into from
Oct 4, 2024
Merged

Conversation

mgupta83
Copy link
Contributor

@mgupta83 mgupta83 commented Oct 4, 2024

This pull request fixes an issue with multiple Apollo clients. The changes include updating the getMemberById function in the MemberDataApiImpl class to use the findById method instead of findOneById. Additionally, the ApolloConnection component now properly sets the Apollo client link based on the client name and includes the necessary dependencies.

Summary by Sourcery

Fix the multiple Apollo clients issue by properly setting the Apollo client link based on the client name and updating the getMemberById function to use findById for better data handling.

Bug Fixes:

  • Fix the issue with multiple Apollo clients by ensuring the Apollo client link is set based on the client name.

Enhancements:

  • Update the getMemberById function in the MemberDataApiImpl class to use the findById method instead of findOneById for improved data retrieval.

@mgupta83 mgupta83 requested a review from gidich as a code owner October 4, 2024 21:52
Copy link
Contributor

sourcery-ai bot commented Oct 4, 2024

Reviewer's Guide by Sourcery

This pull request addresses an issue with multiple Apollo clients by updating the Apollo client configuration in the ApolloConnection component and modifying the getMemberById function in the MemberDataApiImpl class. The changes improve the handling of authentication and optimize the database query for retrieving member data.

Sequence diagram for Apollo client link setup

sequenceDiagram
    actor User
    participant ApolloConnection
    participant ApolloClient
    participant ApolloLink
    participant HttpLink
    participant BatchHttpLink
    participant setContext

    User->>ApolloConnection: Initialize
    ApolloConnection->>setContext: Create withToken context
    ApolloConnection->>ApolloLink: Split link based on clientName
    ApolloLink->>HttpLink: Use countryLink if clientName is 'country'
    ApolloLink->>BatchHttpLink: Use httpLink otherwise
    ApolloConnection->>ApolloClient: Set link
    ApolloClient->>ApolloConnection: Client ready
    ApolloConnection->>User: Provide ApolloProvider with client
Loading

Updated class diagram for MemberDataApiImpl

classDiagram
    class MemberDataApiImpl {
        - findOneById(memberId: string): Promise<MemberData>
        + findById(memberId: string): Promise<MemberData>
        + getMemberById(memberId: string): Promise<MemberData>
    }
Loading

File-Level Changes

Change Details Files
Refactored Apollo client configuration in ApolloConnection component
  • Moved client, httpLink, and countryLink declarations outside of the component
  • Implemented useEffect hook to set the Apollo client link
  • Updated the withToken context to handle unauthenticated scenarios
  • Added console.log for debugging the client link
ui-community/src/components/shared/apollo-connection.tsx
Updated getMemberById function in MemberDataApiImpl class
  • Changed from using findOneById to findById method
  • Simplified the query by chaining the populate method
data-access/src/app/application-services/member/member.data.ts

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@mgupta83 mgupta83 linked an issue Oct 4, 2024 that may be closed by this pull request
Copy link
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 @mgupta83 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider removing the console.log statement in the ApolloConnection component before merging to production.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 1 issue found
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

@mgupta83 mgupta83 merged commit 1ef0bd5 into main Oct 4, 2024
8 checks passed
@mgupta83 mgupta83 deleted the mg-apollo-connection-fix branch October 4, 2024 22:34
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.

Fix Apollo Connection - multiple clients issue
1 participant