@@ -5,7 +5,7 @@ use async_graphql::{
55 dataloader:: { DataLoader , Loader } ,
66 ComplexObject , Context , EmptyMutation , EmptySubscription , Object , Schema , SchemaBuilder ,
77} ;
8- use aws_sdk_s3:: { presigning:: PresigningConfig , Client } ;
8+ use aws_sdk_s3:: presigning:: PresigningConfig ;
99use entities:: {
1010 AutoProcFileAttachment , AutoProcScalingStatics , AutoProcessing , DataCollection , ProcessingJob ,
1111 StatisticsType ,
@@ -29,23 +29,13 @@ pub type RootSchema = Schema<Query, EmptyMutation, EmptySubscription>;
2929/// router handler extension
3030pub trait AddDataLoadersExt {
3131 /// Adds dataloader to graphql request
32- fn add_data_loaders (
33- self ,
34- database : DatabaseConnection ,
35- s3_client : Client ,
36- s3_bucket : S3Bucket ,
37- ) -> Self ;
32+ fn add_data_loaders ( self , database : DatabaseConnection ) -> Self ;
3833}
3934
4035impl AddDataLoadersExt for async_graphql:: Request {
41- fn add_data_loaders (
42- self ,
43- database : DatabaseConnection ,
44- s3_client : Client ,
45- s3_bucket : S3Bucket ,
46- ) -> Self {
36+ fn add_data_loaders ( self , database : DatabaseConnection ) -> Self {
4737 self . data ( DataLoader :: new (
48- FileAttachmentDataLoader :: new ( database. clone ( ) , s3_client , s3_bucket ) ,
38+ FileAttachmentDataLoader :: new ( database. clone ( ) ) ,
4939 tokio:: spawn,
5040 ) )
5141 . data ( DataLoader :: new (
@@ -77,8 +67,6 @@ pub struct Query;
7767pub struct FileAttachmentDataLoader {
7868 database : DatabaseConnection ,
7969 parent_span : Span ,
80- s3_client : Client ,
81- s3_bucket : S3Bucket ,
8270}
8371/// DataLoader for Process Job
8472#[ allow( clippy:: missing_docs_in_private_items) ]
@@ -111,12 +99,10 @@ impl ProcessingJobDataLoader {
11199
112100#[ allow( clippy:: missing_docs_in_private_items) ]
113101impl FileAttachmentDataLoader {
114- fn new ( database : DatabaseConnection , s3_client : Client , s3_bucket : S3Bucket ) -> Self {
102+ fn new ( database : DatabaseConnection ) -> Self {
115103 Self {
116104 database,
117105 parent_span : Span :: current ( ) ,
118- s3_client,
119- s3_bucket,
120106 }
121107 }
122108}
@@ -372,25 +358,6 @@ impl DataCollection {
372358 }
373359}
374360
375- #[ ComplexObject ]
376- impl AutoProcFileAttachment {
377- /// Gives downloadable link for the processed image in the s3 bucket
378- async fn file_url ( & self , ctx : & Context < ' _ > ) -> async_graphql:: Result < String > {
379- let s3_client = ctx. data :: < aws_sdk_s3:: Client > ( ) ?;
380- let bucket = ctx. data :: < S3Bucket > ( ) ?;
381- let object_uri = s3_client
382- . get_object ( )
383- . bucket ( bucket. clone ( ) )
384- . key ( self . object_key ( ) )
385- . presigned ( PresigningConfig :: expires_in ( Duration :: from_secs ( 10 * 60 ) ) ?)
386- . await ?
387- . uri ( )
388- . clone ( ) ;
389- let object_url = Url :: parse ( & object_uri. to_string ( ) ) ?;
390- Ok ( object_url. to_string ( ) )
391- }
392- }
393-
394361#[ ComplexObject ]
395362impl AutoProcessing {
396363 /// Fetches the overall scaling statistics type
@@ -442,6 +409,25 @@ impl AutoProcessing {
442409 }
443410}
444411
412+ #[ ComplexObject ]
413+ impl AutoProcFileAttachment {
414+ /// Gives downloadable link for the processed image in the s3 bucket
415+ async fn file_url ( & self , ctx : & Context < ' _ > ) -> async_graphql:: Result < String > {
416+ let s3_client = ctx. data :: < aws_sdk_s3:: Client > ( ) ?;
417+ let bucket = ctx. data :: < S3Bucket > ( ) ?;
418+ let object_uri = s3_client
419+ . get_object ( )
420+ . bucket ( bucket. clone ( ) )
421+ . key ( self . object_key ( ) )
422+ . presigned ( PresigningConfig :: expires_in ( Duration :: from_secs ( 10 * 60 ) ) ?)
423+ . await ?
424+ . uri ( )
425+ . clone ( ) ;
426+ let object_url = Url :: parse ( & object_uri. to_string ( ) ) ?;
427+ Ok ( object_url. to_string ( ) )
428+ }
429+ }
430+
445431#[ Object ]
446432impl Query {
447433 /// Reference datasets resolver for the router
0 commit comments