-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: enhance hasUserVoted query to include hasVoted #3451
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: enhance hasUserVoted query to include hasVoted #3451
Conversation
WalkthroughThis pull request updates the GraphQL schema and associated resolvers for the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Resolver as "hasUserVoted Resolver"
participant DB as "Database"
User->>Resolver: Query hasUserVoted
Resolver->>DB: Fetch post and organization membership
DB-->>Resolver: Return post and membership details
Resolver->>DB: Check for user's vote on post
DB-->>Resolver: Return vote info or null
Resolver-->>User: Respond with { hasVoted, type }
Assessment against linked issues
Suggested labels
Suggested reviewers
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code Graph Analysis (1)test/graphql/types/Query/hasUserVoted.test.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (4)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
schema.graphql
(3 hunks)src/graphql/types/Post/hasUserVoted.ts
(1 hunks)src/graphql/types/Query/hasUserVoted.ts
(4 hunks)test/graphql/types/Query/hasUserVoted.test.ts
(2 hunks)test/graphql/types/documentNodes.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
test/graphql/types/Query/hasUserVoted.test.ts (2)
test/graphql/types/client.ts (1)
mercuriusClient
(7-9)test/graphql/types/documentNodes.ts (2)
Mutation_createPostVote
(1066-1072)Query_hasUserVoted
(1056-1064)
src/graphql/types/Post/hasUserVoted.ts (3)
src/graphql/builder.ts (1)
builder
(10-20)src/drizzle/enums/postVoteType.ts (1)
postVoteTypeEnum
(6-6)src/graphql/enums/PostVoteType.ts (1)
PostVoteType
(4-7)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run tests for talawa api
- GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (7)
test/graphql/types/documentNodes.ts (1)
1061-1061
: GraphQL query updated correctly to include hasVoted fieldThe Query_hasUserVoted query has been enhanced to include the new hasVoted field, which properly aligns with the updated schema. This change ensures that clients can now check not only the vote type but also explicitly whether a user has voted.
src/graphql/types/Post/hasUserVoted.ts (3)
7-8
: Good addition of hasVoted field and nullable typeThe object reference has been correctly updated to include the new
hasVoted
boolean field while making thetype
field nullable. This change enhances the API by providing more explicit information about the voting status.
13-18
: Well-implemented field definition for hasVotedThe implementation for the
hasVoted
field looks good. It's properly typed as a non-nullable Boolean with an appropriate description and resolver.
21-22
: Clear documentation for nullable type fieldThe nullable flag and updated description clearly communicate that the
type
field can be null when no vote exists, which improves API understanding for consumers.test/graphql/types/Query/hasUserVoted.test.ts (1)
375-375
: Good assertion for hasVoted fieldThe addition of this assertion correctly verifies that
hasVoted
istrue
when a user has actually voted, which complements the test for the case when a user has not voted.schema.graphql (2)
3371-3377
: New Pagination Parameters forgetPledgesByUserId
QueryThe addition of the optional
limit: Int
andoffset: Int
parameters allows callers to control pagination effectively. Please verify that the corresponding resolver logic correctly handles cases where these parameters are omitted (e.g. defaulting to return all results or applying implicit limits).
3534-3552
: Addition of Sorting and Filtering for Pledge QueriesThe reintroduction of the
QueryPledgeOrderByInput
enum—offering values likeamount_ASC
,amount_DESC
,endDate_ASC
, andendDate_DESC
—and the newQueryPledgeWhereInput
(which enables filtering by the creator's first name and campaign name) enhance query flexibility. Make sure the resolver logic is updated to interpret these new inputs appropriately.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3451 +/- ##
====================================================
+ Coverage 59.06% 59.07% +0.01%
====================================================
Files 523 523
Lines 40662 40674 +12
Branches 1732 1735 +3
====================================================
+ Hits 24018 24030 +12
Misses 16635 16635
Partials 9 9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
schema.graphql (1)
776-782
: Enhanced HasUserVoted Type DefinitionThe updated
HasUserVoted
type now clearly exposes a non-nullablehasVoted: Boolean!
field and renames the previoustype
field tovoteType
, which is now nullable. This change improves clarity and better represents the possibility that no vote exists. Please ensure that all client-side queries and resolver implementations are updated accordingly.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
schema.graphql
(3 hunks)src/graphql/types/Post/hasUserVoted.ts
(1 hunks)src/graphql/types/Query/hasUserVoted.ts
(3 hunks)test/graphql/types/Query/hasUserVoted.test.ts
(2 hunks)test/graphql/types/documentNodes.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/graphql/types/Post/hasUserVoted.ts (3)
src/graphql/builder.ts (1)
builder
(10-20)src/drizzle/enums/postVoteType.ts (1)
postVoteTypeEnum
(6-6)src/graphql/enums/PostVoteType.ts (1)
PostVoteType
(4-7)
src/graphql/types/Query/hasUserVoted.ts (1)
src/utilities/TalawaGraphQLError.ts (1)
TalawaGraphQLError
(264-277)
test/graphql/types/Query/hasUserVoted.test.ts (2)
test/graphql/types/client.ts (1)
mercuriusClient
(7-9)test/graphql/types/documentNodes.ts (1)
Query_hasUserVoted
(1056-1064)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Run tests for talawa api
🔇 Additional comments (16)
test/graphql/types/documentNodes.ts (1)
1060-1061
: Good alignment with the updated schema.Adding
voteType
andhasVoted
to the returned fields properly matches the changes introduced in theHasUserVoted
object and ensures the query accurately reflects a user's voting status.src/graphql/types/Post/hasUserVoted.ts (5)
5-5
: No content change for this line.It appears to be a placeholder or formatting adjustment rather than a functional modification. No issue here.
7-8
: Schema fields introduced successfully.Defining
hasVoted
andvoteType
at the objectRef level clarifies the data shape for theHasUserVoted
object, aligning with the new schema requirements.
13-14
: Field definition reflects intended behavior.Using
"Boolean"
as a non-nullable type forhasVoted
helps ensure consistent data usage in clients that consume this API.
16-17
: Proper resolver usage.Resolving
hasVoted
directly from the parent object is straightforward and adheres to GraphQL best practices.
19-22
: Handling nullability with clarity.Exposing
voteType
as a nullable field makes sense given that a user might not have voted at all, sonull
is a valid state.test/graphql/types/Query/hasUserVoted.test.ts (2)
281-303
: Test coverage improvement.Verifying that
voteType
isnull
andhasVoted
isfalse
accurately covers the scenario where no vote record exists, ensuring correctness of the field behaviors.
336-339
: Correct assertions for voted scenario.Checking both
voteType
andhasVoted
ensures the query response is consistent when a vote does exist. This thoroughly tests the new schema fields.src/graphql/types/Query/hasUserVoted.ts (6)
53-54
: Parallel queries for efficiency.Using
Promise.all
to retrieve user, post, and vote data concurrently optimizes wait time and improves performance. Well done.
55-89
: Comprehensive data retrieval in one pass.Fetching user data, post details (including organization and membership), and existing votes in a single set of queries is consistent and maintains clarity in logic. Just ensure the nested relationships remain efficient for large datasets.
97-97
: Clear error handling for missing post.Throwing an
arguments_associated_resources_not_found
error if the post is absent properly aligns with typical GraphQL error patterns.
109-110
: Potential edge case with multiple memberships.Accessing the first element (
[0]
) inmembershipsWhereOrganization
is fine if there is only a single membership. However, if a user can have multiple memberships or roles for the same organization, consider verifying that[0]
is the intended membership or handle multiple entries if needed.
124-129
: Graceful handling of no-vote scenario.Returning an object with
voteType: null
andhasVoted: false
nicely captures the case when a user has not voted. This approach is consistent with the new schema contract.
131-132
: Returning valid vote status.Ensuring
voteType
andhasVoted
are set correctly when a vote exists completes the logic for both voting states, aligning perfectly with the schema updates.schema.graphql (2)
3534-3542
: New Sorting Enum: QueryPledgeOrderByInputThe newly introduced
QueryPledgeOrderByInput
enum (with values such asamount_ASC
,amount_DESC
,endDate_ASC
, andendDate_DESC
) standardizes the sorting criteria used in pledge queries. Ensure that the resolver correctly interprets these enum values so that sorted results are returned as expected.
3544-3551
: New Filter Input: QueryPledgeWhereInputThe
QueryPledgeWhereInput
input type now facilitates filtering pledges by fields like the creator’s first name and the campaign name. This added flexibility is beneficial for more granular queries. You might consider adding additional documentation or even examples (if not already provided elsewhere) on how these filters combine when multiple criteria are passed.
@palisadoes This PR extends a previously closed issue. Earlier, an error was thrown when a user had not voted on a post. Now, this case is handled gracefully by introducing a hasVoted variable, which indicates whether the user has voted on the post. If the user has voted, the voteType (i.e., upvote or downvote) is also included in the response. This PR is ready to be merged. |
3ee59b7
into
PalisadoesFoundation:develop-postgres
What kind of change does this PR introduce?
Issue Number:
Fixes #3426
Snapshots/Videos:
If relevant, did you update the documentation?
Summary
Does this PR introduce a breaking change?
Checklist
CodeRabbit AI Review
Test Coverage
Other information
Have you read the contributing guide?
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Tests