Added new pagination query and mutations to Hashnode API

Author

Fazle Rahman

ยท

improvement
changelog banner

Our public API has undergone significant changes recently. In addition to introducing new features, we have been actively listening to user feedback and making improvements to existing queries. We have added new queries and mutations, that will help you perform pagination on popular articles, and CRUD operations on comment and reply.

Here's what has changed:

Previously when querying for popular tags, you did not have the pagination option. With PopularTagEdge you can find a tag and a cursor for pagination.

Here's an example query for you to try:

query PopularTags($first: Int!) {
  popularTags(first: $first) {
    edges {
      cursor
      node {
        id
        name
        logo
        postsCount
        slug
      }
    }
  }
}

Run it in our API playground to see how it works.

Return deleted posts

Want to query deleted posts? It is now possible with our latest deletedOnly filter.

Using posts resolver you can get the list of posts in a publication. The query returns active posts by default, you need to set the deletedOnly filter to true to return deleted posts.

An example would look like this ๐Ÿ‘‡

New mutations

In this release, we have also added two new mutations for Comment and Reply. You can add, update, delete, like any comment or reply now.

Here's how the new mutations work:

Comment Mutation

  • addComment - Helps you add comments to a post.

    Example query:

      mutation AddComment($input: AddCommentInput!) {
        addComment(input: $input) {
          comment {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            replies {
              ...CommentReplyConnectionFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    
  • likeComment - This lets you add comments to a post.

    An example query would look like this:

      mutation LikeComment($input: LikeCommentInput!) {
        likeComment(input: $input) {
          comment {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            replies {
              ...CommentReplyConnectionFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    
  • removeComment - Using removeComment you can remove comments from a post.

    Example query:

      mutation RemoveComment($input: RemoveCommentInput!) {
        removeComment(input: $input) {
          comment {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            replies {
              ...CommentReplyConnectionFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    
  • updateComment - Use updateComment to update a comment on a post.

    The query would look like this:

      mutation UpdateComment($input: UpdateCommentInput!) {
        updateComment(input: $input) {
          comment {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            replies {
              ...CommentReplyConnectionFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    

Reply mutation

Similar to Comment, you can add, remove, update or like any reply. The newly added mutations are addReply, removeReply, updateReply and likeReply.

Here's an explanation of what each of these mutations does along with examples:

  • addReply - Helps you add a reply to a comment.

    Example query:

      mutation AddReply($input: AddReplyInput!) {
        addReply(input: $input) {
          reply {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    
  • removeReply - Need to remove a reply? You can get it done with removeReply.

    Here's how:

      mutation RemoveReply($input: RemoveReplyInput!) {
        removeReply(input: $input) {
          reply {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }
    
  • updateReply - With updateReply you can easily update a reply.

An example query for you to try:

    mutation UpdateReply($input: UpdateReplyInput!) {
      updateReply(input: $input) {
        reply {
          id
          content {
            ...ContentFragment
          }
          author {
            ...UserFragment
          }
          dateAdded
          stamp
          totalReactions
          myTotalReactions
        }
      }
    }
  • likeReply - You can like a reply using likeReply and an example would be:

      mutation LikeReply($input: LikeReplyInput!) {
        likeReply(input: $input) {
          reply {
            id
            content {
              ...ContentFragment
            }
            author {
              ...UserFragment
            }
            dateAdded
            stamp
            totalReactions
            myTotalReactions
          }
        }
      }