Skip to content

Commit

Permalink
Make QueryStore::api_version() bound to ApiVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela committed Jun 20, 2022
1 parent ad0b6ea commit 763228f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion graph/src/components/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub trait QueryStore: Send + Sync {
/// return details about it needed for executing queries
async fn deployment_state(&self) -> Result<DeploymentState, QueryExecutionError>;

fn api_schema(&self, api_version: &ApiVersion) -> Result<Arc<ApiSchema>, QueryExecutionError>;
fn api_schema(&self) -> Result<Arc<ApiSchema>, QueryExecutionError>;

fn network_name(&self) -> &str;

Expand Down
4 changes: 2 additions & 2 deletions graphql/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ where
let store = self.store.query_store(target.clone(), false).await?;
let state = store.deployment_state().await?;
let network = Some(store.network_name().to_string());
let schema = store.api_schema(target.get_version())?;
let schema = store.api_schema()?;

// Test only, see c435c25decbc4ad7bbbadf8e0ced0ff2
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -271,7 +271,7 @@ where
target: QueryTarget,
) -> Result<SubscriptionResult, SubscriptionError> {
let store = self.store.query_store(target.clone(), true).await?;
let schema = store.api_schema(&target.get_version())?;
let schema = store.api_schema()?;
let network = store.network_name().to_string();

let query = crate::execution::Query::new(
Expand Down
7 changes: 5 additions & 2 deletions store/postgres/src/query_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) struct QueryStore {
replica_id: ReplicaId,
store: Arc<DeploymentStore>,
chain_store: Arc<crate::ChainStore>,
api_version: Arc<ApiVersion>,
}

impl QueryStore {
Expand All @@ -21,12 +22,14 @@ impl QueryStore {
chain_store: Arc<crate::ChainStore>,
site: Arc<Site>,
replica_id: ReplicaId,
api_version: Arc<ApiVersion>,
) -> Self {
QueryStore {
site,
replica_id,
store,
chain_store,
api_version,
}
}
}
Expand Down Expand Up @@ -101,8 +104,8 @@ impl QueryStoreTrait for QueryStore {
.await?)
}

fn api_schema(&self, api_version: &ApiVersion) -> Result<Arc<ApiSchema>, QueryExecutionError> {
let info = self.store.subgraph_info(&self.site, api_version)?;
fn api_schema(&self) -> Result<Arc<ApiSchema>, QueryExecutionError> {
let info = self.store.subgraph_info(&self.site, &self.api_version)?;
Ok(info.api)
}

Expand Down
12 changes: 10 additions & 2 deletions store/postgres/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ impl QueryStoreManager for Store {
graph::prelude::QueryExecutionError,
> {
let store = self.subgraph_store.cheap_clone();
let api_version = target.get_version();
let target = target.clone();
let (store, site, replica) = graph::spawn_blocking_allow_panic(move || {
store
.replica_for_query(target, for_subscription)
.replica_for_query(target.clone(), for_subscription)
.map_err(|e| e.into())
})
.await
Expand All @@ -92,7 +94,13 @@ impl QueryStoreManager for Store {
)
})?;

Ok(Arc::new(QueryStore::new(store, chain_store, site, replica)))
Ok(Arc::new(QueryStore::new(
store,
chain_store,
site,
replica,
Arc::new(api_version.clone()),
)))
}
}

Expand Down

0 comments on commit 763228f

Please sign in to comment.