A feature rich API for blog-like applications in GraphQL using Apollo.
Handles image-upload, uses web-sockets for live feed, authentication using JWT and graphQL server using the apollo library.
graphql
├───graphql (GraphQL resolvers and schema.)
├───middlewares (Contains the Auth middleware which validates JWT token.)
├───models (Auth and Feed Schema for MongoDB.)
└───utils (Utilities folder.)
Dev
Node.js, Apollo Server, Socket.io, Mongoose, Sendgrid
- Clone this repo:
git clone https://github.com/guptapriyanshu7/graphql
- Run
npm install
- Setup environment variables :
- Create a
.env
file in root directory of the project - Insert these 3 keys/value pairs :
- PORT : < Port on which server will listen >
- MONGO_URI : < Mongo database connection URI >
- SECRET : < Secret for jwt tokens >
- Create a
- Start the server:
npm start
- Start requesting from http://localhost:PORT/graphql.
mutation CreatePost($postInput: PostInputData!) {
createPost(postInput: $postInput) {
title
content
imageUrl
createdAt
}
}
mutation UpdatePost($id: ID!, $postInput: PostUpdateData!) {
updatePost(id: $id, postInput: $postInput) {
title
content
imageUrl
createdAt
}
}
query SinglePost($id: ID!) {
post(id: $id) {
title
content
imageUrl
}
}
query Login($email: String!, $password: String!) {
login(email: $email, password: $password) {
token
userId
}
}
subscription {
postCreated {
_id
title
content
}
}
query GetPosts($page: Int) {
getPosts(page: $page) {
totalPosts
posts {
_id
title
content
}
}
}
mutation Register($userInput: UserInputData!) {
createUser(userInput: $userInput) {
_id
}
}
query {
user {
_id
name
}
}
mutation DeletePost($id: ID!) {
deletePost(id: $id)
}
Frontend - https://post-node-web.herokuapp.com/
REST alternative - https://github.com/guptapriyanshu7/rest-api
This project is licensed under the MIT License, © 2021 Priyanshu Gupta. See LICENSE for more details.