From 0d3fb8d1de4d0a0281c845f87b196d283f848c41 Mon Sep 17 00:00:00 2001 From: Nicolai Unrein Date: Mon, 30 Mar 2020 16:02:43 +0200 Subject: [PATCH 1/4] add documentation to upload --- src/types/upload.rs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/types/upload.rs b/src/types/upload.rs index 31e540fe..b35ce15c 100644 --- a/src/types/upload.rs +++ b/src/types/upload.rs @@ -1,9 +1,50 @@ use crate::{registry, InputValueType, Type, Value}; use std::borrow::Cow; -/// Upload file type +/// Uploaded file /// -/// Reference: https://github.com/jaydenseric/graphql-multipart-request-spec +/// **Reference:** +/// +/// +/// Graphql supports file uploads via `multipart/form-data`. +/// Enable this feature by accepting an argument of type `Upload` (single file) or +/// `Vec` (multiple files) in your mutation like in the example blow. +/// +/// +/// # Example +/// *[Full Example]()* +/// +/// ``` +/// use async_graphql::Upload; +/// +/// struct MutationRoot; +/// +/// #[async_graphql::Object] +/// impl MutationRoot { +/// #[field] +/// async fn upload(&self, file: Upload) -> bool { +/// println!( +/// "upload: filename={} size={}", +/// file.filename, +/// file.content.len() +/// ); +/// true +/// } +/// } +/// +/// ``` +/// # Example Curl Request +/// Assuming you have defined your mutation root like in the example above, you can now upload a file `myFile.txt` with the below curl +/// command: +/// +/// ```curl +/// curl POST 'localhost:8000' \ +/// --form 'operations={ +/// "query": "mutation ($file: Upload!) { upload(file: $file) }", +/// "variables": { "file": null }}' \ +/// --form 'map={ "0": ["variables.file"] }' \ +/// --form '0=@myFile.txt' +/// ``` pub struct Upload { /// Filename pub filename: String, From 6944a542bb86865c2398649799af46d6c9882c57 Mon Sep 17 00:00:00 2001 From: nicolaiunrein Date: Mon, 30 Mar 2020 16:31:38 +0200 Subject: [PATCH 2/4] Update upload.rs --- src/types/upload.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/upload.rs b/src/types/upload.rs index b35ce15c..8b338727 100644 --- a/src/types/upload.rs +++ b/src/types/upload.rs @@ -34,8 +34,8 @@ use std::borrow::Cow; /// /// ``` /// # Example Curl Request -/// Assuming you have defined your mutation root like in the example above, you can now upload a file `myFile.txt` with the below curl -/// command: +/// Assuming you have defined your mutation root like in the example above, +/// you can now upload a file `myFile.txt` with the below curl command: /// /// ```curl /// curl POST 'localhost:8000' \ From 9eaf445cc25dd0293247a6b3e92c47a1677cd97d Mon Sep 17 00:00:00 2001 From: nicolaiunrein Date: Mon, 30 Mar 2020 16:36:27 +0200 Subject: [PATCH 3/4] Update upload.rs --- src/types/upload.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/upload.rs b/src/types/upload.rs index 8b338727..953f0265 100644 --- a/src/types/upload.rs +++ b/src/types/upload.rs @@ -34,7 +34,7 @@ use std::borrow::Cow; /// /// ``` /// # Example Curl Request -/// Assuming you have defined your mutation root like in the example above, +/// Assuming you have defined your MutationRoot like in the example above, /// you can now upload a file `myFile.txt` with the below curl command: /// /// ```curl From 0da2f900a14e0d8d02d845bf86eeeff33b685aea Mon Sep 17 00:00:00 2001 From: nicolaiunrein Date: Mon, 30 Mar 2020 16:47:17 +0200 Subject: [PATCH 4/4] Update upload.rs --- src/types/upload.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/upload.rs b/src/types/upload.rs index 953f0265..79859a84 100644 --- a/src/types/upload.rs +++ b/src/types/upload.rs @@ -38,7 +38,7 @@ use std::borrow::Cow; /// you can now upload a file `myFile.txt` with the below curl command: /// /// ```curl -/// curl POST 'localhost:8000' \ +/// curl 'localhost:8000' \ /// --form 'operations={ /// "query": "mutation ($file: Upload!) { upload(file: $file) }", /// "variables": { "file": null }}' \