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§
source§impl InputType for Upload
impl InputType for Upload
§type RawValueType = Upload
type RawValueType = Upload
The raw type used for validator. Read more
source§fn 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.
source§fn parse(value: Option<Value>) -> InputValueResult<Self>
fn parse(value: Option<Value>) -> InputValueResult<Self>
Parse from
Value
. None represents undefined.source§fn as_raw_value(&self) -> Option<&Self::RawValueType>
fn as_raw_value(&self) -> Option<&Self::RawValueType>
Returns a reference to the raw value.
source§fn qualified_type_name() -> String
fn qualified_type_name() -> String
Qualified typename.