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

Full 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

Get the upload value.

Trait Implementations

The raw type used for validator. Read more

Type the name.

Create type information in the registry and return qualified typename.

Parse from Value. None represents undefined.

Convert to a Value for introspection.

Returns a reference to the raw value.

Qualified typename.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more