Giter VIP home page Giter VIP logo

graphql_fastapi's Introduction

CRUD Operation GraphQL FastAPI with MongoDB

This is a sample project that demonstrates a CRUD operation GraphQL API using FastAPI, MongoDB, and Strawberry.

Installation

  1. Clone the repository:
git clone https://github.com/Shikha-code36/GraphQL_FastAPI.git

cd GraphQL_FastAPI
  1. Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate # On Linux/MacOS
venv\Scripts\activate.bat # On Windows
  1. Install dependencies using pip:
pip install -r requirements.txt

Usage

  1. Make sure your MongoDB server is running on localhost at the default port 27017. You can use your MongoDB server instead of localhost.

  2. Start the FastAPI server:

uvicorn main:app --reload
  1. The GraphQL API will be available at http://localhost:8000/graphql. You can access this URL in your browser or use tools like Insomnia or GraphQL Playground to interact with the API.

Test

To run the test cases, use the following command:

python -m pytest

Examples

Create User

To create a new user, send a GraphQL mutation request:

mutation {
  createUser(name: "Shikha Pandey") {
    id
    name
  }
}

Update User

To update a user, send a GraphQL mutation request:

mutation {
  updateUser(id: 1, name: "Kritika Pandey") {
    id
    name
  }
}

Delete User

To delete a user, send a GraphQL mutation request:

mutation {
  deleteUser(id: 1) {
    id
    name
  }
}

Get All Users

To get a list of all users, send a GraphQL query request:

query {
  users {
    id
    name
  }
}

Get User by ID

To get a specific user by ID, send a GraphQL query request:

query {
  user(id: 1) {
    id
    name
  }
}

[Note:] Please adjust the URLs, ports, and API endpoints according to your setup.

License

This project is licensed under the MIT License.

Disclaimer

This project is a basic implementation of a graphql and python FastApi for educational purposes. It may not be suitable for production use. Use it at your own risk.

Contributing

Contributions to this project are welcome. If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

graphql_fastapi's People

Contributors

shikha-code36 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

iamsenorespana

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.