Struct async_graphql::types::Upload
source · [−]pub struct Upload(_);
Expand description
Uploaded file
Reference: https://github.com/jaydenseric/graphql-multipart-request-spec
Graphql supports file uploads via multipart/form-data
.
Enable this feature by accepting an argument of type Upload
(single file)
or Vec<Upload>
(multiple files) in your mutation like in the example blow.
Example
use async_graphql::*;
struct Mutation;
#[Object]
impl Mutation {
async fn upload(&self, ctx: &Context<'_>, file: Upload) -> bool {
println!("upload: filename={}", file.value(ctx).unwrap().filename);
true
}
}
Example Curl Request
Assuming you have defined your Mutation like in the example above,
you can now upload a file myFile.txt
with the below curl command:
curl 'localhost:8000' \
--form 'operations={
"query": "mutation ($file: Upload!) { upload(file: $file) }",
"variables": { "file": null }}' \
--form 'map={ "0": ["variables.file"] }' \
--form '0=@myFile.txt'
Implementations
Trait Implementations
sourceimpl InputType for Upload
impl InputType for Upload
type RawValueType = Upload
type RawValueType = Upload
The raw type used for validator. Read more
sourcefn create_type_info(registry: &mut Registry) -> String
fn create_type_info(registry: &mut Registry) -> String
Create type information in the registry and return qualified typename.
sourcefn parse(value: Option<Value>) -> InputValueResult<Self>
fn parse(value: Option<Value>) -> InputValueResult<Self>
Parse from
Value
. None represents undefined.sourcefn as_raw_value(&self) -> Option<&Self::RawValueType>
fn as_raw_value(&self) -> Option<&Self::RawValueType>
Returns a reference to the raw value.
sourcefn qualified_type_name() -> String
fn qualified_type_name() -> String
Qualified typename.
Auto Trait Implementations
impl RefUnwindSafe for Upload
impl Send for Upload
impl Sync for Upload
impl Unpin for Upload
impl UnwindSafe for Upload
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more