simnova / ownercommunity

MIT License
5 stars 1 forks source link

Fix multiple Apollo clients issue #319

Closed mgupta83 closed 23 hours ago

mgupta83 commented 1 day ago

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:

Enhancements:

sourcery-ai[bot] commented 1 day ago

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

Updated class diagram for MemberDataApiImpl

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

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](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).