Hacker News

A Django project that implements a simple news application with GraphQL support. This project demonstrates the use of Django and GraphQL for building APIs.

Features

  • User authentication with JWT
  • Create and manage links
  • Query users and links with GraphQL

Requirements

  • Python 3.6 or later
  • Django 2.1.4
  • Graphene-Django 2.2.0
  • GraphQL-JWT

Installation

  1. Clone the Repository

    git clone https://github.com/yourusername/your-repo.git
    cd your-repo
  2. Set Up a Virtual Environment

    python3 -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install Dependencies

    pip install -r requirements.txt
  4. Apply Migrations

    python manage.py migrate
  5. Create a Superuser (Optional)

    python manage.py createsuperuser
  6. Run the Development Server

    python manage.py runserver

    Open your browser and navigate to http://127.0.0.1:8000/graphql/ to access the GraphQL API.

Usage

  • GraphQL Endpoints

    • Query Links

      query {
        links {
          id
          url
          description
        }
      }
    • Create a Link

      mutation {
        createLink(url: "https://example.com", description: "Example Link") {
          id
          url
          description
        }
      }
  • User Authentication

    • Obtain JSON Web Token

      mutation {
        tokenAuth(username: "yourusername", password: "yourpassword") {
          token
        }
      }
    • Verify Token

      mutation {
        verifyToken(token: "yourjwt") {
          payload
        }
      }
    • Refresh Token

      mutation {
        refreshToken(token: "yourjwt") {
          token
        }
      }

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements