Skip to content

Commit

Permalink
feat: add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
coratgerl committed Jan 31, 2025
1 parent e6d8272 commit 63a78ea
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 25 deletions.
21 changes: 12 additions & 9 deletions packages/wabe-buns3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ yarn add wabe-buns3 # On yarn

```ts
import { DatabaseEnum, Wabe } from "wabe";
import { ResendAdapter } from "wabe-resend";
import { Buns3Adapter } from "wabe-buns3";

const run = async () => {
// Ensure your database is running before run the file
Expand All @@ -41,20 +41,23 @@ const run = async () => {
url: "mongodb://127.0.0.1:27045",
name: "WabeApp",
},
email: {
adapter : new ResendAdapter("YOUR_RESEND_API_KEY"),
file: {
adapter : new Buns3Adapter({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
bucket: 'bucketName',
endpoint: 'endpoint',
}),
}
port: 3000,
});

await wabe.start();

await wabe.controllers.email.send({
from : "test@test.com",
to: ["target@gmail.com"],
subject: "Test",
text: "Test",
});
// The upload file and the read file is automatically managed in the GraphQL API
await wabe.controllers.file.uploadFile(new File(['test'], 'test.txt'));

const url = await wabe.controllers.file.readFile('test.txt');
};

await run();
Expand Down
4 changes: 4 additions & 0 deletions packages/wabe-documentation/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export default defineConfig({
},
],
},
{
text: 'File',
link: '/file/index.md',
},
{
text: 'Email',
link: '/email/index.md',
Expand Down
97 changes: 97 additions & 0 deletions packages/wabe-documentation/docs/file/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# File

Wabe allow you to store files very easily, with a fully automatic integration in the GraphQL API. You can upload files, read them, and delete them. Wabe will automatically manage the files and the database, so you don't have to worry about it.

## Configuration

To configure your adapter you can for example use the `Buns3Adapter` :

```ts
import { DatabaseEnum, Wabe } from "wabe";
import { Buns3Adapter } from "wabe-buns3";

const run = async () => {
// Ensure your database is running before run the file

const wabe = new Wabe({
// Root key example (must be long minimal 64 characters, you can generate it online)
rootKey:
"0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*",
database: {
type: DatabaseEnum.Mongo,
url: "mongodb://127.0.0.1:27045",
name: "WabeApp",
},
file: {
adapter : new Buns3Adapter({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
bucket: 'bucketName',
endpoint: 'endpoint',
}),
}
port: 3000,
});

await wabe.start();

// The upload file and the read file is automatically managed in the GraphQL API
await wabe.controllers.file.uploadFile(new File(['test'], 'test.txt'));

const url = await wabe.controllers.file.readFile('test.txt');
};

await run();
```

## GraphQL API

The GraphQL API automatically manages the upload, the read and the delete of the files. You can use it like this :

```graphql
query users {
users {
edges {
node {
id
avatar {
name # The name of the file
url # The url of the file
}
}
}
}
}
```

Example to create a file :

```ts
const formData = new FormData();

formData.append(
"operations",
JSON.stringify({
query: `mutation (avatar: File!) {
updateUser(input: {id: \"userId\", fields: {avatar: $avatar}}) {
user {
id
avatar {
url
}
}
}
}`,
variables: { avatar: null },
}),
);

formData.append("map", JSON.stringify({ 0: ["variables.avatar"] }));

formData.append("0", new File(["a"], "a.text", { type: "text/plain" }));

const res = await fetch("http://127.0.0.1:3000/graphql", {
method: "POST",
body: formData,
});
```
16 changes: 0 additions & 16 deletions packages/wabe-documentation/docs/graphql/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,19 +339,3 @@ const res = await fetch("http://127.0.0.1:3000/graphql", {
body: formData,
});
```

Example of adapter implementation in schema :

```ts
new Wabe({
// ... others config fields
file: {
adapter: async (file) => {
// ... Upload the file on a bucket

// return the url of the file for example (this url will be store in the database)
return "http://bucket.storage/123456/logo.webp";
},
},
});
```

0 comments on commit 63a78ea

Please sign in to comment.