Skip to content

samisyd/GraphQLProj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Item Management API

A simple GraphQL API built with FastAPI and Strawberry for managing items in a SQLite database.

Features

  • Query all items or fetch a specific item by ID
  • Create new items with name and price
  • GraphQL playground for testing queries and mutations
  • SQLite database for persistent storage

Prerequisites

  • Python 3.8+
  • pip or uv package manager

Installation

  1. Clone or download this project
  2. Install dependencies:
    pip install -r requirements.txt
    Or using uv:
    uv add -r requirements.txt

Setup

Database Initialization

Before running the app, initialize the database:

python setup_db.py

This script:

  • Creates the SQLite database file (items.db)
  • Creates the items table with columns: id, name, and price
  • Populates the database with sample data (Apple and Banana items)

Note: Running this script multiple times will not overwrite existing data (uses CREATE TABLE IF NOT EXISTS), so it's safe to run multiple times.

Running the Application

Start the FastAPI server:

python main.py

The server will run on http://localhost:8000

GraphQL Endpoint

Access the GraphQL playground at:

http://localhost:8000/graphql

API Usage

Query Examples

Get all items:

query {
  items {
    id
    name
    price
  }
}

Get a specific item by ID:

query {
  item(id: 1) {
    id
    name
    price
  }
}

Mutation Examples

Create a new item:

mutation {
  createItem(name: "Laptop", price: 999.99) {
    id
    name
    price
  }
}

Project Structure

  • app.py - GraphQL schema and resolvers
  • main.py - FastAPI application entry point
  • setup_db.py - Database initialization script
  • requirements.txt - Python dependencies
  • pyproject.toml - Project configuration

Database

The app uses SQLite with the database file items.db. The items table has the following structure:

Column Type Description
id INTEGER Primary key
name TEXT Item name
price REAL Item price

Dependencies

  • fastapi - Web framework
  • strawberry-graphql - GraphQL implementation
  • uvicorn - ASGI server
  • sqlite3 - Database (built-in)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages