Code Monkey home page Code Monkey logo

ipfs_service's Introduction

Rust + Axum + Prisma

A template for creating services in Rust using Axum and Prisma. This uses the super cool Prisma Rust Client.

Getting Started

You'll want to have cargo-watch installed for the best DX, however it isn't required.

cargo install cargo-watch

Then you can run the cargo-watch -x run command to watch for changes and automatically rebuild the project.

Prisma

To set up prisma, run:

cargo prisma generate # outputs client to src/prisma.rs
cargo prisma db push # outputs sqlite db to prisma/dev.db (specified in schema.prisma)
cargo seed # seeds the database with some data (unimplemented, create a seed based on your needs)

For more in-depth information about the prisma client, see the Prisma Client Rust Docs.

Run the Server

To run the server, run:

cargo run # or cargo-watch -x run

GraphQL Playground

Go to localhost:8080/api/graphql to see the playground. You can see the schema and the docs, but a few examples would be:

# Create user
mutation {
  createUser(input: { displayName: "oromei" }) {
    id
  }
}

# Create post
mutation {
  createPost(
    input: {
      content: "Woah there!"
      userId: "5ab80953-c38c-4ec8-8b4b-3ecc4bc1196f"
    }
  ) {
    id
    content
    user {
      displayName
    }
  }
}

# Get all users
query {
  getUsers {
    id
    displayName
  }
}

# Get all posts
query {
  getPosts {
    id
    content
    user {
      displayName
    }
  }
}

Notes

This template uses Axum, but the bulk of the setup is for async_graphql + prisma. You should be able to easily swap out Axum for your preferred framework (e.g. Rocket, actix, etc).

The simple use of async_graphql means that queries are done in a less efficient manner than could be, since fetching relations using with is never utilized and relations are loaded separately. Additionally, dataloader is not utilized because I can't be bothered.

ipfs_service's People

Contributors

born99 avatar

Watchers

 avatar

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.