diff --git a/packages/wabe-buns3/README.md b/packages/wabe-buns3/README.md index 620648ef..25c1e5c4 100644 --- a/packages/wabe-buns3/README.md +++ b/packages/wabe-buns3/README.md @@ -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 @@ -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(); diff --git a/packages/wabe-documentation/docs/.vitepress/config.ts b/packages/wabe-documentation/docs/.vitepress/config.ts index 08c880d0..bdabf71a 100644 --- a/packages/wabe-documentation/docs/.vitepress/config.ts +++ b/packages/wabe-documentation/docs/.vitepress/config.ts @@ -173,6 +173,10 @@ export default defineConfig({ }, ], }, + { + text: 'File', + link: '/file/index.md', + }, { text: 'Email', link: '/email/index.md', diff --git a/packages/wabe-documentation/docs/file/index.md b/packages/wabe-documentation/docs/file/index.md new file mode 100644 index 00000000..cb0aa916 --- /dev/null +++ b/packages/wabe-documentation/docs/file/index.md @@ -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, +}); +``` diff --git a/packages/wabe-documentation/docs/graphql/api.md b/packages/wabe-documentation/docs/graphql/api.md index fea51962..82232e84 100644 --- a/packages/wabe-documentation/docs/graphql/api.md +++ b/packages/wabe-documentation/docs/graphql/api.md @@ -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"; - }, - }, -}); -```