Skip to content

Commit

Permalink
Allow additional headers when persisting
Browse files Browse the repository at this point in the history
Specific headers in the config (use JS config for dynamic values)
```
persist: {
  url: "https://persist-service/path",
  headers: {
    Authorization: "bearer TOKEN",
  },
}
```

And they'll sent along on the request
```
POST https://persist-service/path
Content-Type: application/x-www-form-urlencoded
Authorization: bearer TOKEN
```
  • Loading branch information
tomgasson committed Oct 29, 2022
1 parent af2be51 commit 75209d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

use std::iter::empty;

use async_trait::async_trait;
use persist_query::persist;
use persist_query::PersistError;
Expand Down Expand Up @@ -35,14 +33,16 @@ impl OperationPersister for RemotePersister {
artifact: ArtifactForPersister,
) -> Result<String, PersistError> {
let params = &self.config.params;
let headers = &self.config.headers;

let url = &self.config.url;
if let Some(semaphore) = &self.semaphore {
let permit = (*semaphore).acquire().await.unwrap();
let result = persist(&artifact.text, url, params, empty()).await;
let result = persist(&artifact.text, url, params, headers).await;
drop(permit);
result
} else {
persist(&artifact.text, url, params, empty()).await
persist(&artifact.text, url, params, headers).await
}
}
}
4 changes: 4 additions & 0 deletions compiler/crates/relay-config/src/project_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct RemotePersistConfig {
#[serde(default)]
pub params: FnvIndexMap<String, String>,

/// Additional headers to send
#[serde(default)]
pub headers: FnvIndexMap<String, String>,

#[serde(
default,
rename = "concurrency",
Expand Down

0 comments on commit 75209d5

Please sign in to comment.