File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 11import  Foundation
2+ import  DataCompression
23
34public  final  class  GraphQLClient  { 
45    public  let  endpoint :  URL 
@@ -34,6 +35,15 @@ public final class GraphQLClient {
3435        let  gqlRequest  =  GraphQLRequest ( query:  query,  variables:  variables,  operationName:  operationName) 
3536        var  request  =  URLRequest ( url:  endpoint) 
3637        request. httpMethod =  " POST " 
38+         
39+         let  rawData  =  try . httpBody ( ) 
40+         if  let  compressedData =  rawData. gzip ( )  { 
41+           request. httpBody =  compressedData
42+           request. setValue ( " gzip " ,  forHTTPHeaderField:  " Content-Encoding " ) 
43+         }  else  { 
44+           request. httpBody =  rawData
45+         } 
46+ 
3747        request. httpBody =  try . httpBody ( ) 
3848
3949        print ( " 🔹Sending request:  \( String ( data:  request. httpBody!,  encoding:  . utf8)  ??  " (no body) " ) " ) 
@@ -42,6 +52,9 @@ public final class GraphQLClient {
4252        combinedHeaders. forEach  {  request. setValue ( $0. value,  forHTTPHeaderField:  $0. key)  } 
4353
4454        let  data  =  try await  network. send ( request) 
55+  
56+         
57+         print ( " GraphQL response:  \( String ( data:  data,  encoding:  . utf8)  ??  " (no data) " ) " ) 
4558
4659        do  { 
4760            let  envelope  =  try . decode ( GraphQLResponse< Output> . self ,  from:  data) 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments