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

getExerciseComment and getChildComments GraphQL queries #2480

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

HS-90
Copy link
Collaborator

@HS-90 HS-90 commented Nov 1, 2022

Description: relates to #2400

This PR adds two GraphQL resolvers for getting exercise comments(filtered by exerciseId), and getting child comments(filtered by parentId). When implemented on the frontend, the getExerciseComment will get any main comments, and it's replies. Any nested replies beyond the first reply to main comments will be retrieved with getChildComments.

To test:
First we need to add comments

  1. Go to 'api/graphql'
  2. Write 3 mutations as follows:

mutation AddExerciseComment{ addExerciseComment(exerciseId:1, content:"Cool"){ id exerciseId content } }

mutation AddExerciseComment{ addExerciseComment(exerciseId:1, parentId: 1, content:" Really Really COOL!"){ id exerciseId parentId content } }

mutation AddExerciseComment{ addExerciseComment(exerciseId:1, parentId: 1, content:"Cool bro"){ id exerciseId parentId content } }

Getting Exercise Comments
3. Write a query to get all main comments with ExerciseId 1:
query GetExerciseComments{ getExerciseComments(exerciseId:1){ id createdAt exerciseId parentId content replies{ id createdAt content } } }

It should return something like this:
getExerciseComments query

Getting Child Comments
4. Write a query to get all exerciseComment with parentId of 1:

query GetChildComments{ getChildComments(parentId:1){ id createdAt exerciseId parentId content } }

It should return something like this:
image

@vercel
Copy link

vercel bot commented Nov 1, 2022

@HS-90 is attempting to deploy a commit to the c0d3-prod Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Nov 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
c0d3-app ✅ Ready (Inspect) Visit Preview Nov 2, 2022 at 5:27PM (UTC)

@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #2480 (a96ed23) into master (55940b9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #2480   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          186       186           
  Lines         3316      3324    +8     
  Branches       881       881           
=========================================
+ Hits          3316      3324    +8     
Impacted Files Coverage Δ
graphql/resolvers/exerciseCommentCrud.ts 100.00% <100.00%> (ø)

return prisma.exerciseComment.findMany({
where: { parentId: null, exerciseId },
include: {
replies: true
Copy link
Member

Choose a reason for hiding this comment

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

This will only include the exercise comment replies and not the replies nested replies like

// Main exercise comment
{
  replies: [
    {
      // ...props -> It won't have this, right?
      replies: []
    }
    // reply2...etc
  ]
}

Copy link
Member

Choose a reason for hiding this comment

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

I think the answer is no

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right it will retrieve all the 'main' comments and one nested layer of replies below that, then we use the getChildComments query to get the nested replies beyond that level.

Copy link
Member

@flacial flacial left a comment

Choose a reason for hiding this comment

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

Looks good! In a following PR, we can create their query files which will help in creating their hooks.

@HS-90
Copy link
Collaborator Author

HS-90 commented Nov 2, 2022

Looks good! In a following PR, we can create their query files which will help in creating their hooks.

Thanks. Will do that in the next PR

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