-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add missing /cost GraphQL API back
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023-, GraphOps and Semiotic Labs. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema}; | ||
use async_graphql_axum::{GraphQLRequest, GraphQLResponse}; | ||
use axum::extract::Extension; | ||
|
||
use crate::{ | ||
common::{ | ||
indexer_error::IndexerError, | ||
indexer_management::{self, CostModel}, | ||
}, | ||
server::ServerOptions, | ||
}; | ||
|
||
pub type CostSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>; | ||
|
||
#[derive(Default)] | ||
pub struct QueryRoot; | ||
|
||
#[Object] | ||
impl QueryRoot { | ||
async fn cost_models( | ||
&self, | ||
ctx: &Context<'_>, | ||
deployments: Vec<String>, | ||
) -> Result<Vec<CostModel>, IndexerError> { | ||
let pool = &ctx.data_unchecked::<ServerOptions>().indexer_management_db; | ||
indexer_management::cost_models(pool, &deployments).await | ||
} | ||
|
||
async fn cost_model( | ||
&self, | ||
ctx: &Context<'_>, | ||
deployment: String, | ||
) -> Result<Option<CostModel>, IndexerError> { | ||
let pool = &ctx.data_unchecked::<ServerOptions>().indexer_management_db; | ||
indexer_management::cost_model(pool, &deployment).await | ||
} | ||
} | ||
|
||
pub(crate) async fn graphql_handler( | ||
req: GraphQLRequest, | ||
Extension(schema): Extension<CostSchema>, | ||
Extension(server_options): Extension<ServerOptions>, | ||
) -> GraphQLResponse { | ||
schema | ||
.execute(req.into_inner().data(server_options)) | ||
.await | ||
.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters