Skip to content

Commit 3c01675

Browse files
committed
Added Readme and app environment variables
1 parent fde462a commit 3c01675

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DATABASE_URL=postgres://[username]:[password]@localhost/[database_name]
2+
MEILISEARCH_HOST=http://localhost:7700
3+
MEILISEARCH_API_KEY=[your-master-key]
4+
MIGRATIONS_DIR_PATH=migrations

examples/web_app_graphql/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target
2+
/Cargo.lock
3+
4+
.env

examples/web_app_graphql/Readme.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Meilisearch example with graphql using `diesel`, `async_graphql` and `postgres`
2+
3+
## Contents
4+
5+
Setting up a graphql server using `async_graphql` and `actix-web`
6+
7+
Using `diesel` to query the database
8+
9+
Using `meilisearch-sdk` to search for records that match a given criteria
10+
11+
## Running the example
12+
13+
The meilisearch server needs to be running. You can run it by the command below
14+
15+
```bash
16+
meilisearch --master-key <your master key>
17+
```
18+
19+
Then you can run the application by simply running
20+
21+
```bash
22+
cargo run --release
23+
```
24+
25+
The above command will display a link to your running instance and you can simply proceed by clicking the link or navigating to your browser.
26+
27+
### Running the resolvers
28+
29+
On your browser, you will see a graphql playground in which you can use to run some queries
30+
31+
You can use the `searchUsers` query as follows:
32+
33+
```gpl
34+
query {
35+
users{
36+
search(queryString: "Eugene"){
37+
lastName
38+
firstName
39+
email
40+
}
41+
}
42+
}
43+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use serde::Deserialize;
2+
3+
#[derive(Deserialize, Debug, Clone)]
4+
pub struct AppEnvVars {
5+
pub meilisearch_api_key: String,
6+
pub meilisearch_host: String,
7+
pub database_url: String,
8+
pub migrations_dir_path: String,
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use async_graphql::SimpleObject;
2+
use diesel::{Queryable, Selectable};
3+
use serde::{Deserialize, Serialize};
4+
5+
use crate::schema::users;
6+
7+
#[derive(SimpleObject, Deserialize, Serialize, Queryable, Selectable, Debug)]
8+
#[diesel(table_name = users)]
9+
pub struct User {
10+
pub id: i32,
11+
pub first_name: String,
12+
pub last_name: String,
13+
pub email: String,
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @generated automatically by Diesel CLI.
2+
3+
diesel::table! {
4+
users (id) {
5+
id -> Int4,
6+
first_name -> Varchar,
7+
last_name -> Varchar,
8+
email -> Varchar,
9+
}
10+
}

0 commit comments

Comments
 (0)