Skip to content

Commit

Permalink
featL added misc, publications and post mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinesamuel committed Nov 18, 2024
1 parent 46ffbe6 commit 0c19743
Show file tree
Hide file tree
Showing 8 changed files with 1,484 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/managers/misc/misc.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import {
} from './misc.queries';
import type {
CommenterUserConnection,
FollowTagsInput,
FollowTagsPayload,
Tag,
UnfollowTagsInput,
UnfollowTagsPayload,
} from '../../generated/gqlQueryTypes';
import { FOLLOW_TAGS_MUTATION, UNFOLLOW_TAGS_MUTATION } from './misc.mutations';

/**
* Manages random operations.
Expand Down Expand Up @@ -54,4 +59,44 @@ export class MiscellaneousManager extends BaseManager {
);
return res.tag;
}

/**
*
* ===================MUTATIONS===================
*
*/

/**
* Follow tags
*
* @param input - The followTag input.
*
* @returns The tag details.
*/
async followTags(input: FollowTagsInput) {
const res = await this.makeRequest<{ followTag: FollowTagsPayload }>(
'followTaga',
FOLLOW_TAGS_MUTATION,
{ input },
);
return res.followTag;
}

/**
* Unfollow tags
*
* @param input - The UnFollowTag input.
*
* @returns The tag details.
*/
async unfollowTags(input: UnfollowTagsInput) {
const res = await this.makeRequest<{ unfollowTag: UnfollowTagsPayload }>(
'unfollowTags',
UNFOLLOW_TAGS_MUTATION,
{ input },
);
return res.unfollowTag;
}


}
39 changes: 39 additions & 0 deletions src/managers/misc/misc.mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { gql } from 'graphql-request';

export const FOLLOW_TAGS_MUTATION = gql`
mutation followTags($input: FollowTagsInput!) {
followTags(input: $input) {
tags {
id
name
slug
logo
tagline
info {
markdown
}
followersCount
postsCount
}
}
}
`

export const UNFOLLOW_TAGS_MUTATION = gql`
mutation followTags($input: UnfollowTagsInput!) {
unfollowTags(input: $input) {
tags {
id
name
slug
logo
tagline
info {
markdown
}
followersCount
postsCount
}
}
}
`
98 changes: 98 additions & 0 deletions src/managers/posts/post.manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { PublishPostInput, AddPostToSeriesInput, UpdatePostInput, RemovePostInput, LikePostInput, LikePostPayload, RemovePostPayload, UpdatePostPayload, AddPostToSeriesPayload, PublishPostPayload } from './../../generated/gqlQueryTypes';
import type { HashnodeSDKClient } from '../../client';
import { BaseManager } from '../base.manager';
import {
Expand All @@ -10,6 +11,7 @@ import {
type PostLikerFilter,
} from '../../generated/gqlQueryTypes';
import {
ADD_POST_TO_SERIES_MUTATION,
GET_DRAFT_POST_QUERY,
GET_FEED_POST,
GET_POST_COMMENTERS,
Expand All @@ -18,6 +20,10 @@ import {
GET_POST_PUBLICATION_QUERY,
GET_POST_QUERY,
GET_SCHEDULED_POST_QUERY,
LIKE_POST_MUTATION,
PUBLISH_POST_MUTATION,
REMOVE_POST_MUTATION,
UPDATE_POST_MUTATION,
} from './post.queries';

/**
Expand Down Expand Up @@ -192,4 +198,96 @@ export class PostManager extends BaseManager {
);
return res.feedPost;
}

/**
* Publish a post
*
* @param {PublishPostInput} input - The post to be published
*
* @returns The new post
*/
async publishPost(input: PublishPostInput) {
const res = await this.makeRequest<{ publishedpost: PublishPostPayload }>(
'publishPost',
PUBLISH_POST_MUTATION,
{
input
}
)
return res.publishedpost.post
}

/**
* Add a post to a series
*
* @param {AddPostToSeriesInput} input - The input of the post to be added to the series
*
* @return The series
*/
async addPostToSeries(input: AddPostToSeriesInput) {
const res = await this.makeRequest<{ series: AddPostToSeriesPayload }>(
'addPostToSeries',
ADD_POST_TO_SERIES_MUTATION,
{
input
}
)
return res.series
}

/**
* Updates a post
*
* @param {UpdatePostInput} input - The input of the post to be updated
*
* @return The updated post
*/
async updatePost(input: UpdatePostInput) {
const res = await this.makeRequest<{ updatedPost: UpdatePostPayload }>(
'updatePost',
UPDATE_POST_MUTATION,
{
input
}
)
return res.updatedPost
}

/**
* Remove a post
*
* @param {RemovePostInput} input - The input of the post to be removed
*
* @return The removed post
*/
async removePost(input: RemovePostInput) {
const res = await this.makeRequest<{ removedPost: RemovePostPayload }>(
'removePost',
REMOVE_POST_MUTATION,
{
input
}
)
return res.removedPost
}

/**
* Like a post
*
* @param {LikePostInput} input - The input of the post to be liked
*
* @return The liked post
*/
async likePost(input: LikePostInput) {
const res = await this.makeRequest<{ likedPost: LikePostPayload }>(
'likePost',
LIKE_POST_MUTATION,
{
input
}
)
return res.likedPost
}


}
Loading

0 comments on commit 0c19743

Please sign in to comment.