{"id":13880558,"url":"https://github.com/lucperkins/rust-graphql-juniper-actix-diesel-postgres","last_synced_at":"2025-04-07T07:11:45.190Z","repository":{"id":75187335,"uuid":"230531945","full_name":"lucperkins/rust-graphql-juniper-actix-diesel-postgres","owner":"lucperkins","description":"An example GraphQL server written in Rust","archived":false,"fork":false,"pushed_at":"2024-07-20T20:07:49.000Z","size":91,"stargazers_count":255,"open_issues_count":3,"forks_count":32,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-11T23:39:10.364Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucperkins.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["lucperkins"]}},"created_at":"2019-12-27T23:24:14.000Z","updated_at":"2024-07-20T20:07:53.000Z","dependencies_parsed_at":"2024-07-20T21:53:57.505Z","dependency_job_id":"a70836be-030c-4b70-8b64-fb5ea29cd843","html_url":"https://github.com/lucperkins/rust-graphql-juniper-actix-diesel-postgres","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucperkins%2Frust-graphql-juniper-actix-diesel-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucperkins%2Frust-graphql-juniper-actix-diesel-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucperkins%2Frust-graphql-juniper-actix-diesel-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucperkins%2Frust-graphql-juniper-actix-diesel-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucperkins","download_url":"https://codeload.github.com/lucperkins/rust-graphql-juniper-actix-diesel-postgres/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608153,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:03:11.909Z","updated_at":"2025-04-07T07:11:45.161Z","avatar_url":"https://github.com/lucperkins.png","language":"Rust","funding_links":["https://github.com/sponsors/lucperkins"],"categories":["Rust"],"sub_categories":[],"readme":"# Rust + GraphQL + Juniper + Diesel + Postgres + Actix\n\nYes, I know that this is a borderline absurd web stack for the ubiquitous TODO application but I had a *lot* of trouble getting this all to work. I started using these things for a more ambitious project and I'd love to spare you the trouble. So here's some basic boilerplate to get you up and running.\n\n## Components\n\nHere's what does what:\n\nComponent | Tool/lib\n:---------|:--------\nWeb server | [actix-web](https://github.com/actix/actix-web)\nDatabase | [PostgreSQL](https://postgresql.org)\nSQL engine | [Diesel](https://diesel.rs)\nGraphQL library | [Juniper](https://github.com/graphql-rust/juniper)\nGraphQL UI | [GraphQL Playground](https://github.com/prisma-labs/graphql-playground)\n\n## Run locally\n\n\u003e Before you get started, make sure that you have [PostgreSQL](https://postgresql.org), [Rust](https://rust-lang.org), [Cargo](https://doc.rust-lang.org/cargo/), and the [Diesel](https://diesel.rs) CLI installed and that you have Postgres running somewhere.\n\n```bash\n# Fetch the repo\ngit clone https://github.com/lucperkins/rust-actix-diesel-postgres-juniper\ncd rust-actix-diesel-postgres-juniper\n\n# If you would like to run the postgres server in docker\ndocker compose up\n\n# Set up the database\ncp .env.example .env # Modify this file to match your Postgres installation\n\ndiesel setup\ndiesel migration run\n\ncargo run # could take a while!\n```\n\n\u003e The `DATABASE_URL` can be any Postgres installation. For my purposes, I have it set to `postgres://localhost:5432/todos`.\n\nOnce the server is running, you can access the GraphQL Playground UI at http://localhost:4000/graphql.\n\n## Schema\n\nThe server implements the following GraphQL schema:\n\n```graphql\ntype Todo {\n  id: ID!\n  task: String!\n  done: Boolean!\n}\n\ninput CreateTodoInput {\n  task: String!\n  done: Boolean\n}\n\ntype Query {\n  allTodos: [Todo!]!\n  getTodoById(id: Int): Todo\n}\n\ntype Mutation {\n  createTodo(input: CreateTodoInput): Todo\n  markTodoAsDone(id: Int): Todo\n  markTodoAsNotDone(id: Int): Todo\n}\n\nschema {\n  Query\n  Mutation\n}\n```\n\n## Tour of the codebase\n\nFile | What it provides\n:----|:----------------\n[`context.rs`](./src/context.rs) | The GraphQL [context](https://graphql.org/learn/execution) that handles query execution\n[`data.rs`](./src/data.rs) | A `Todos` struct and some helper functions encapsulate the [Diesel](https://diesel.rs)-powered Postgres querying logic\n[`db.rs`](./src/db.rs) | The connection pool that handles the Postgres connection\n[`endpoints.rs`](./src/endpoints.rs) | The `/graphql` HTTP endpoint that makes GraphQL and the GraphQL Playground work\n[`graphql.rs`](./src/graphql.rs) | The `Query`, `Mutation`, and `Schema` objects that undergird the GraphQL interface\n[`lib.rs`](./src/lib.rs) | Just the standard `lib.rs`\n[`main.rs`](./src/main.rs) | [Actix](https://actix.rs) HTTP server setup\n[`models.rs`](./src/models.rs) | All of the data types used for querying Postgres and providing GraphQL results\n[`schema.rs`](./src/schema.rs) | The Diesel-generated table schema\n\n## Future TODOs\n\nGet it? Anyway, here's some areas for improvement (pull requests very much welcome):\n\n* **Error handling** — Right now errors basically propagate directly from Diesel/Postgres into the GraphQL JSON output, which is subpar. If any of you can point me to good educational resources on this, please file an issue!\n* **Better execution engine** — The server uses the extremely powerful [actix-web](https://github.com/actix/actix-web) but the actual DB interactions don't use Actix actors and it'd take this setup to the next level if they did.\n* **Use macros for schema generation** — The powerful [`juniper_from_schema`](https://docs.rs/juniper-from-schema/0.5.1/juniper_from_schema/) macro could help reduce boilerplate and improve development velocity.\n\n## Acknowledgments\n\nI'm basically a beginner with Rust and would not have been able to put this together without peeking long and hard at the example projects and blog posts listed below. The lower-level bits you see here are basically stolen from [BrendanBall](https://github.com/BrendanBall). All that I've added is the [`Todos`](./src/data.rs) data construct for executing queries.\n\n### Example projects\n\n* [BrendanBall/example-actix-web-juniper-diesel](https://github.com/BrendanBall/example-actix-web-juniper-diesel)\n* [iwilsonq/rust-graphql-example](https://github.com/iwilsonq/rust-graphql-example)\n* [dancespiele/listing_people_api_actix](https://github.com/dancespiele/listing_people_api_actix)\n\n### Blog posts\n\n* [Building Powerful GraphQL Servers with Rust](https://dev.to/open-graphql/building-powerful-graphql-servers-with-rust-3gla)\n* [[Rust] juniper + diesel + actix-webでGraphQLしてみる](https://qiita.com/yagince/items/e378bbaa95e08bab7467)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucperkins%2Frust-graphql-juniper-actix-diesel-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucperkins%2Frust-graphql-juniper-actix-diesel-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucperkins%2Frust-graphql-juniper-actix-diesel-postgres/lists"}