Clone the project
$ git clone [email protected]:aiotrope/obiter.git myproject
$ cd myproject
Install the dependencies
$ npm install
Create .env
file at the root of the project directory and setup the environment variables
.
The 2 required variables are: MONGO_DEV
, and TOKEN_SECRET
.
e.g.
# .env
MONGO_DEV=mongodb://localhost:27017/mydb # MongoDB URL connection string
JWT_KEY=b2e5943db539285644c838de0015a3ffc2c2cf3a11104adeb280a06cb0ba46f3fc70503d7b5a4d66362050ff01236161 # as secret key
Run the code
# serve backend at localhost:4000
$ npm run dev
User Model
- email: String
- hash: hashed password
- posts: Array of posts made by the user; reference to PostModel
- commnentsMade: Array of comments created by the user; reference to CommentModel
Post Model
- title: String
- postedBy: Object; reference to user who create the post
- comments: Array of comments belong to the post
Comment Model
- text: String
- commenter: Object; reference to user who made the comment
- commentFor: Object; reference to PostModel for which the comment is made
User Signup
mutation SIGNUP($email: String!, $password: String!) {
signup(email: $email, password: $password) {
id
email
posts {
id
}
commentsMade {
id
}
}
}
Login
mutation SIGNIN($email: String!, $password: String!) {
signin(email: $email, password: $password) {
value
}
}
Post Creation
require authorization token
mutation CREATE_POST($title: String) {
createPost(title: $title) {
id
title
comments {
id
text
}
postedBy {
id
email
}
}
}
All Posts
query POSTS {
posts {
id
title
comments {
id
text
}
postedBy {
id
email
}
}
}
Post Subscription
require authorization token
subscription POST_ADDED {
postAdded {
id
title
comments {
id
text
}
postedBy {
id
email
}
}
}
Update Post
require authorization token
mutation UPDATE_POST($postId: ID!, $updatePostInput: UpdatePostInput!) {
updatePost(postId: $postId, updatePostInput: $updatePostInput) {
id
title
comments {
id
text
}
postedBy {
id
email
}
}
}
Updated Post Subscription
require authorization token
subscription POST_UPDATED {
postUpdated {
id
title
comments {
id
text
}
postedBy {
id
email
}
}
}
Create Comment
require authorization token
mutation CREATE_COMMENT($postId: String!, $commentInput: CommentInput!) {
createComment(postId: $postId, commentInput: $commentInput) {
id
text
commenter {
id
email
}
commentFor {
id
title
}
}
}
All Comments
query COMMENTS {
comments {
id
text
commentFor {
id
title
}
commenter {
id
email
}
}
}
Comment Subscription
require authorization token
subscription COMMENT_ADDED {
commentAdded {
id
text
commenter {
id
email
}
commentFor {
id
title
}
}
}