Skip to content

Instantly share code, notes, and snippets.

@Godtide
Last active August 23, 2021 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Godtide/3b1802bb71660a010cab827118b710e6 to your computer and use it in GitHub Desktop.
Save Godtide/3b1802bb71660a010cab827118b710e6 to your computer and use it in GitHub Desktop.
Why KeystoneJs for a Basic social media app
WHY KEYSTONEJS
KeystoneJS is a powerful Node.js web app framework built on express and mongoose.
Keystone makes it easy to build faster and scale further than any other App Framework.
Just describe your schema, and get a powerful GraphQLAPI (query language).
The GraphQLAPI makes KeystoneJs the most suitable Node.js framework to build a social media application
as GraphQLAPI harmonizes with the Graph-like nature of data in a social media application
BENEFITS of GraphQLAPI
A)GraphQL is perfect for social media application. There’s less to worry about when it comes to fetching data,
it reduces overFetching of data(too many request) to the server, and underfetching(not enough response) from the server.
B)Faster performance
GraphQL requests will always be smaller and more efficient, which reduces request to the server
because multiple entities can be retrieved in one request, further adding to each query’s efficiency
and doesn’t encounter call limits as quickly since it uses fewer queries and only returns what the client asked for specifically.
C) Reduces Over-Fetching or too many request to the server
In our social media app. The feed might display the most recent posts from all users, along with the usernames and profile pics which
making a GET request for every user, there'll a be lot of back and forth for one page (too many calls on endpoints),
buit with GraphQL, it's possible to make one request to the server and get a response with everything needed
query {
posts {
postId: string
title: string
description: string
createdAt: timestamp
commentsCount: int
deletedAt?: timestamp
user {
username,
avatar,
type?
}
}
}
API DESIGN
USER
A user can can create posts and write comments on any post, A user will be of two types, an admin user , and non-admin User.
An admin User can delete any comment, non-admin can only delete it's comments and post.
USER
{
id: String
username: String
type?: enum ADMIN/NON
}
POSTS
Posts will have an id, the User, a description and a title, and a timestamp of when they're created.
Posts will also have comments.
Lastly, Posts will have optional deletedAt and currentVote fields.
POST {
postId: string
title: string
description: string
createdAt: timestamp
commentsCount: int
deletedAt?: timestamp
user {
username,
avatar,
type?
}
}
CreatePost, EditPost, GetPost, and DeletePost methods will be very straightforward. One thing to note, however, is that all of these operations will take in the userId of the user performing them; this id, which will contain authentication information, will be used for ACL checks to see if the user performing the operations has the necessary permission(s) to do so.
CreatePost{User{}, title: string, description: string)
=> Post
EditPost(User{}, postId: string, title: string, description: string)
=> Post
GetPost(User{}, postId: string)
=>Post
DeletePost(User{}, postId: string, type?: enum)
=> Post
As a social media app grows, our ListPosts method will have to be paginated. The method will take in optional pageSize and pageToken parameters and will return a list of posts of at most length pageSize as well as a nextPageToken--the token to be fed to the method to retrieve the next page of posts.
ListPosts(User{} pageSize?: int, pageToken?: string)
=> (Post[], nextPageToken?)
COMMENTS
Comments will be similar to Posts. They'll have an id, the creator/User.
COMMENTS {
commentId: string
postId: string
createdAt: timestamp
content: string
postId?: string
deletedAt?: timestamp
creator {
username,
avatar,
type?
}
}
The CRUD operations for Comments will be very similar to those for Posts, except that the CreateComment method will also take in an optional postId pointing to the post that it's commenting on.
CreateComment(Creator{}, postId: string, content: string, parentId?: string)
=> Comment
EditComment(Creator{}, commentId: string, content: string)
=> Comment
GetComment(Creator{}, commentId: string)
=> Comment
DeleteComment(Creator{}, commentId: string, type? enum)
=> Comment
ListComments(Creator{}, postId: string, pageSize?: int, pageToken?: string)
=> (Comment[], nextPageToken?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment