Skip to content

A Social Media Api created with TypeScript, Express, Express-GraphQL, TypeORM, PostgreSQL

License

Notifications You must be signed in to change notification settings

ahmdhusam/social-media

Repository files navigation

Social Media Server App

Express, GraphQL, MongoDB example

License

How to run the project

Required:

node.js: v18.4

Install dependencies:

yarn
# or using npm
npm install

Now create a file called .env in the project root and add the following variables, replacing the values with your own.

.env

PGPORT={Postgres port URL}
PGNAME={Database name}
PGPASSWORD={Database password}
PORT={Port} // Default 3300
SECRET_KEY={Secret Key For JWT}
ADMIN_ACCESS={Token to access Logs folder}

Run the project:

yarn start
# or using npm
npm start

Open GraphiQL in your browser http://localhost:PORT/graphql

Example Queries

Create new User:

mutation {
  createUser(
    user: {
      name: "Luke Skywalker"
      userName: "luke_skywalker"
      email: "[email protected]"
      birthDate: "1996-1-11"
      gender: "male"
      password: "strongPassword"
    }
  ) {
    name
    userName
    email
    birthDate
    gender
    avatar
  }
}

Login To Get Access Token Back (You have to put the access token in the authorization header like "Bearer [access_token]"):

query {
  login(loginContent: { email: "[email protected]", password: "12345678" }) {
    id
    access_token
    name
    userName
    email
    tweets {
      content
      creator {
        userName
      }
      replys {
        content
        creator {
          userName
        }
      }
    }
  }
}

Return the current user:

mutation {
  me {
    id
    name
    userName
    email
    bio
    birthDate
    gender
    avatar
    header
    createdAt
    tweets {
      id
      content
      replys {
        content
        creator {
          userName
        }
      }
    }
    followings {
      id
      name
      userName
      avatar
      header
    }
    followers {
      id
      name
      userName
      avatar
      header
    }
  }
}

Create new Tweet:

mutation {
  createTweet(tweet: { content: "Tweet 1" }) {
    id
    content
    replys {
      content
    }
    creator {
      userName
    }
  }
}

Retweet:

mutation {
  retweet(tweetId: "0ac7bc4b-e0ac-4d33-abdf-725fa9351827") {
    id
    content
    creator {
      userName
    }
  }
}

Add Reply To Tweet:

mutation {
  addReply(reply: { tweetId: "0ac7bc4b-e0ac-4d33-abdf-725fa9351827", content: "Reply 1" }) {
    id
    content
    creator {
      userName
      email
    }
    replys {
      id
      content
      creator {
        userName
      }
      replys {
        content
        creator {
          userName
        }
      }
    }
  }
}

Get a Specific Tweet:

query {
  getTweet(tweetId: "0ac7bc4b-e0ac-4d33-abdf-725fa9351827") {
    id
    content
    replys {
      content
      creator {
        userName
      }
    }
    creator {
      userName
    }
  }
}

Follow Another User:

mutation {
  follow(userId: "4920b7c7-01d6-41e2-bf1e-249c2ee65e1d") {
    id
    name
    userName
    email
    followers {
      id
      name
      userName
      email
    }
  }
}

Unfollow a User You Already Follow:

mutation {
  unfollow(userId: "4920b7c7-01d6-41e2-bf1e-249c2ee65e1d") {
    name
    userName
  }
}

Delete Tweet (It Will Delete all Nested Replies):

mutation {
  deleteTweet(tweetId: "0ac7bc4b-e0ac-4d33-abdf-725fa9351827") {
    content
    replys {
      id
      content
      replys {
        id
        content
        creator {
          userName
        }
      }
      creator {
        userName
      }
    }
    creator {
      userName
    }
  }
}

Update User Password:

mutation {
  changePassword(passwords: { old: "strongPassword", new: "lukesky123" }) {
    id
    name
    userName
    email
  }
}

Get a Specific User:

query {
  getUser(userName: "luke_skywalker") {
    id
    name
    userName
    tweets {
      id
      content
      creator {
        userName
      }
    }
  }
}

Get List Of Tweets (Ordered By Most Recent):

query {
  getTimeline {
    id
    content
    replys {
      id
      content
      creator {
        userName
      }
    }
    creator {
      name
      userName
    }
  }
}

License

MIT license