Skip to content

Commit

Permalink
server: add graph-node version to index-node API
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Sep 11, 2023
1 parent 11222da commit e8ee79a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/index-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ http = "0.2"
hyper = "0.14"
lazy_static = "1.2.0"
serde = "1.0"
git-testament = "0.2.4"
34 changes: 34 additions & 0 deletions server/index-node/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::convert::TryInto;
use graph::data::query::Trace;
use web3::types::Address;

use git_testament::{git_testament, CommitKind};
use graph::blockchain::{Blockchain, BlockchainKind, BlockchainMap};
use graph::components::store::{BlockPtrForNumber, BlockStore, EntityType, Store};
use graph::components::versions::VERSIONS;
Expand All @@ -18,6 +19,19 @@ use crate::auth::PoiProtection;
/// Timeout for calls to fetch the block from JSON-RPC or Firehose.
const BLOCK_HASH_FROM_NUMBER_TIMEOUT: Duration = Duration::from_secs(10);

git_testament!(TESTAMENT);

lazy_static! {
static ref VERSION: Version = Version {
version: env!("CARGO_PKG_VERSION").to_string(),
commit: match TESTAMENT.commit {
CommitKind::FromTag(_, hash, _, _) => hash.to_string(),
CommitKind::NoTags(hash, _) => hash.to_string(),
_ => "unknown".to_string(),
}
};
}

#[derive(Clone, Debug)]
struct PublicProofOfIndexingRequest {
pub deployment: DeploymentHash,
Expand All @@ -39,6 +53,21 @@ impl TryFromValue for PublicProofOfIndexingRequest {
}
}

#[derive(Clone, Debug)]
struct Version {
version: String,
commit: String,
}

impl IntoValue for Version {
fn into_value(self) -> r::Value {
object! {
version: self.version,
commit: self.commit,
}
}
}

#[derive(Debug)]
struct PublicProofOfIndexingResult {
pub deployment: DeploymentHash,
Expand Down Expand Up @@ -469,6 +498,10 @@ impl<S: Store> IndexNodeResolver<S> {
))
}

fn version(&self) -> Result<r::Value, QueryExecutionError> {
Ok(VERSION.clone().into_value())
}

async fn block_ptr_for_number(
&self,
network: String,
Expand Down Expand Up @@ -700,6 +733,7 @@ impl<S: Store> Resolver for IndexNodeResolver<S> {
(None, "entityChangesInBlock") => self.resolve_entity_changes_in_block(field),
// The top-level `subgraphVersions` field
(None, "apiVersions") => self.resolve_api_versions(field),
(None, "version") => self.version(),

// Resolve fields of `Object` values (e.g. the `latestBlock` field of `EthereumBlock`)
(value, _) => Ok(value.unwrap_or(r::Value::Null)),
Expand Down
6 changes: 6 additions & 0 deletions server/index-node/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ type Query {
entityChangesInBlock(subgraphId: String!, blockNumber: Int!): EntityChanges!
blockData(network: String!, blockHash: Bytes!): JSONObject
blockHashFromNumber(network: String!, blockNumber: Int!): Bytes
version: Version!
cachedEthereumCalls(
network: String!
blockHash: Bytes!
): [CachedEthereumCall!]
apiVersions(subgraphId: String!): [ApiVersion!]!
}

type Version {
version: String!
commit: String!
}

type SubgraphIndexingStatus {
subgraph: String!
synced: Boolean!
Expand Down

0 comments on commit e8ee79a

Please sign in to comment.