Skip to content

A feature rich GraphQL API for blog-like applications using the Apollo library.

License

Notifications You must be signed in to change notification settings

guptapriyanshu7/graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostNode GraphQL Server

GitHub issues GitHub stars GitHub forks GitHub license

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.

Folder Structure

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.)

Tools

  • Dev Node.js, Apollo Server, Socket.io, Mongoose, Sendgrid

Local Setup

  • 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 >
  • Start the server: npm start
  • Start requesting from http://localhost:PORT/graphql.

Example Queries

  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

License

This project is licensed under the MIT License, © 2021 Priyanshu Gupta. See LICENSE for more details.

About

A feature rich GraphQL API for blog-like applications using the Apollo library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages