Struct async_graphql::types::Upload
source · pub struct Upload(pub usize);
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'
Tuple Fields§
§0: usize
Implementations§
Methods from Deref<Target = usize>§
pub const MIN: usize = 0usize
pub const MAX: usize = 18_446_744_073_709_551_615usize
pub const BITS: u32 = 64u32
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.
source§impl Ord for Upload
impl Ord for Upload
source§impl PartialEq for Upload
impl PartialEq for Upload
source§impl PartialOrd for Upload
impl PartialOrd for Upload
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Upload
impl Eq for Upload
impl StructuralPartialEq for Upload
Auto Trait Implementations§
impl Freeze for Upload
impl RefUnwindSafe for Upload
impl Send for Upload
impl Sync for Upload
impl Unpin for Upload
impl UnwindSafe for Upload
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.