Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
2b6ab1e
graph: Add UnvalidatedSubgraphManifest
Nov 18, 2019
719bba7
core, graph: Update subgraph manifest resolution
Nov 18, 2019
cfa183a
graph: Add SchemaReference enum and remove Schema method
Nov 18, 2019
ebae6f0
schema: Add imported_schemas method to Schema
Nov 19, 2019
f70804a
core, graph: SchemaReferences are being resolved
Nov 21, 2019
01f55e1
core, graph: Validation of imported subgraphs
Nov 25, 2019
408cfd6
graph: Validate Schema fields
Nov 27, 2019
1eace39
core, graph: Address warnings
Nov 27, 2019
a88e04f
core, graph: Move resolve_schema_references to method on Schema
Dec 2, 2019
82e734e
core: Update combinator order subgraph deploy
Dec 3, 2019
5acf36e
graph: Update schema type name const
Dec 3, 2019
8c43beb
graph: Simplify combinators
Dec 3, 2019
7ceffc2
graph: Update comments
Dec 3, 2019
add1bd7
graph: Remove comment and add placeholder method
Dec 3, 2019
f3cf585
graph: Remove extra method on UnvalidateSubgraphManifest
Dec 3, 2019
5d7dfa3
graph: Detect cycles in graph when resolving imports
Dec 3, 2019
8b53793
schema: Better validation for import directives
Dec 4, 2019
6d0fe09
graph: Validate imported types exists in schema
Dec 4, 2019
8eb4abe
graph: Update SchemaReference type
Dec 6, 2019
8f75eac
graph: Validated subgraph name and id in imports directives
Dec 6, 2019
be3491a
graph: Migrate the tests to schema
Dec 6, 2019
3b3bcda
graph: Update assertions on test
Dec 6, 2019
ba3a328
graph: Update fail string
Dec 7, 2019
1453a89
graph: Edit fail string
Dec 7, 2019
59ba60b
graph: Remove superfluous comments
Dec 7, 2019
7d1025e
graph: Update comments
Dec 7, 2019
3eb1731
graph: Add validation tests for imported schemas
Dec 8, 2019
ea5f178
graph: Update tests for validating imported types
Dec 8, 2019
2219852
graph: Rename method on Schema
Dec 8, 2019
509f225
graph: Shorten validation with if let
Dec 9, 2019
52db556
graph: Remove extra whitespace
Dec 9, 2019
1401b9f
graph: Propogate warnings
Dec 9, 2019
650d938
graph: _schema -> _Schema_
Dec 13, 2019
4230217
core: Rename cloned loggers and stores
Dec 17, 2019
886819f
core, graph: Validate network names in UnvalidatedSubgraphManifest
Dec 17, 2019
b4a1abb
core: Log the validation warnings
Dec 17, 2019
2950821
graph: Implement TryFrom<&str> for BuiltInScalarType
Dec 17, 2019
2121cff
graph, graphql: Move graphql AST extension traits to graph crate
Dec 18, 2019
a3db611
schema: Add backticks in error msg around type name
Dec 18, 2019
7a80b69
graph: Reanme SchemaValidationError enum variants
Dec 18, 2019
8fcfabb
graph: Address naming and msg feedback
Dec 18, 2019
e4f75da
graph: Remove TODO and make tuple values private
Dec 18, 2019
8d02fb3
graph: Address comments about errors and hashing
Dec 18, 2019
9fb0afd
graph: Address schema.rs comment from review
Dec 18, 2019
72552c3
graph: Overload variable names
Dec 19, 2019
24a2483
graph: Address validation comments
Dec 19, 2019
67f5c56
graph: Better use of combinators
Dec 19, 2019
8713b29
graph: Leaner pattern matching
Dec 19, 2019
214d44b
graph: Better pattern matching
Dec 19, 2019
a308077
graph: Address feedback on collecting errors
Dec 19, 2019
17f5d84
graph: Tests passing
Dec 20, 2019
8976ca0
graphql: Initial implementation of `merged_schema`
Dec 22, 2019
c612581
graphql: Add placeholder type in case where schema is not found
Dec 22, 2019
e62eafd
graphql: Import nonscalar fields of imported types, add tests cases
Dec 23, 2019
cd83cd8
graphql: Remove unused import
Dec 23, 2019
fb4a302
graph, graphql: Add tests for merged_schema
Dec 30, 2019
5950601
graphql: Define @originalName directive, update comments
Jan 3, 2020
d6f08a0
graph, graphql, mock, store: Integrate merged_schema with Store
Jan 3, 2020
47efb3a
graphql: Remove extra import
Jan 3, 2020
88e0f4c
graph, mock, store: Use SchemaImportError
Jan 3, 2020
d24ab6a
store: Implement cache invalidation
Jan 5, 2020
94a9577
store: Update comment
Jan 5, 2020
4f0436b
graphql, server: Remove redundant code
Jan 10, 2020
2b12994
mock: Ensure Store is correctly mocked
Jan 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/subgraph/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
host_metrics: Arc<HostMetrics>,
) -> Result<Self, Error> {
let subgraph_id = manifest.id.clone();
let network = manifest.network_name()?;
let network = manifest.network_name();
let templates = manifest.templates;

let mut this = SubgraphInstance {
Expand Down
78 changes: 34 additions & 44 deletions core/src/subgraph/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,52 +247,42 @@ impl SubgraphInstanceManager {
"Start subgraph";
"data_sources" => manifest.data_sources.len()
);

match manifest.network_name() {
Ok(n) => {
Self::start_subgraph(
logger.clone(),
instances.clone(),
host_builder.clone(),
block_stream_builder.clone(),
stores
.get(&n)
.expect(&format!(
"expected store that matches subgraph network: {}",
&n
))
.clone(),
eth_adapters
.get(&n)
.expect(&format!(
"expected eth adapter that matches subgraph network: {}",
&n
))
.clone(),
manifest,
metrics_registry_for_subgraph.clone(),
)
.map_err(|err| {
error!(
logger,
"Failed to start subgraph";
"error" => format!("{}", err),
"code" => LogCode::SubgraphStartFailure
)
})
.and_then(|_| {
manager_metrics.subgraph_count.inc();
Ok(())
})
.ok();
}
Err(err) => error!(
let network = manifest.network_name();
Self::start_subgraph(
logger.clone(),
instances.clone(),
host_builder.clone(),
block_stream_builder.clone(),
stores
.get(&network)
.expect(&format!(
"expected store that matches subgraph network: {}",
&network
))
.clone(),
eth_adapters
.get(&network)
.expect(&format!(
"expected eth adapter that matches subgraph network: {}",
&network
))
.clone(),
manifest,
metrics_registry_for_subgraph.clone(),
)
.map_err(|err| {
error!(
logger,
"Failed to start subgraph";
"error" => format!("{}", err),
"error" => format!("{}", err),
"code" => LogCode::SubgraphStartFailure
),
};
)
})
.and_then(|_| {
manager_metrics.subgraph_count.inc();
Ok(())
})
.ok();
}
SubgraphStop(id) => {
let logger = logger_factory.subgraph_logger(&id);
Expand Down Expand Up @@ -338,7 +328,7 @@ impl SubgraphInstanceManager {

// Clone the deployment ID for later
let deployment_id = manifest.id.clone();
let network_name = manifest.network_name()?;
let network_name = manifest.network_name();

// Obtain filters from the manifest
let log_filter = EthereumLogFilter::from_data_sources(&manifest.data_sources);
Expand Down
1 change: 0 additions & 1 deletion core/src/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod instance_manager;
mod loader;
mod provider;
mod registrar;
mod validation;

pub use self::instance::SubgraphInstance;
pub use self::instance_manager::SubgraphInstanceManager;
Expand Down
110 changes: 60 additions & 50 deletions core/src/subgraph/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ lazy_static! {
);
}

use super::validation;
use graph::data::subgraph::schema::{
generate_entity_id, SubgraphDeploymentAssignmentEntity, SubgraphDeploymentEntity,
SubgraphEntity, SubgraphVersionEntity, TypedEntity,
Expand All @@ -40,7 +39,7 @@ impl<L, P, S, CS> SubgraphRegistrar<L, P, S, CS>
where
L: LinkResolver + Clone,
P: SubgraphAssignmentProviderTrait,
S: Store,
S: Store + SubgraphDeploymentStore,
CS: ChainStore,
{
pub fn new(
Expand Down Expand Up @@ -275,7 +274,7 @@ impl<L, P, S, CS> SubgraphRegistrarTrait for SubgraphRegistrar<L, P, S, CS>
where
L: LinkResolver,
P: SubgraphAssignmentProviderTrait,
S: Store,
S: Store + SubgraphDeploymentStore,
CS: ChainStore,
{
fn create_subgraph(
Expand All @@ -296,70 +295,81 @@ where
hash: SubgraphDeploymentId,
node_id: NodeId,
) -> Box<dyn Future<Item = (), Error = SubgraphRegistrarError> + Send + 'static> {
let store = self.store.clone();
let store_for_validation = self.store.clone();
let store_for_subgraph_version = self.store.clone();
let chain_stores = self.chain_stores.clone();
let ethereum_adapters = self.ethereum_adapters.clone();
let version_switching_mode = self.version_switching_mode;

let logger = self.logger_factory.subgraph_logger(&hash);
let logger2 = logger.clone();
let logger3 = logger.clone();
let logger_for_subgraph_version = logger.clone();
let logger_for_debug = logger.clone();
let name_inner = name.clone();

Box::new(
SubgraphManifest::resolve(hash.to_ipfs_link(), self.resolver.clone(), logger.clone())
.map_err(SubgraphRegistrarError::ResolveError)
.and_then(validation::validate_manifest)
.and_then(move |manifest| {
manifest
.network_name()
.map_err(|e| SubgraphRegistrarError::ManifestValidationError(vec![e]))
.and_then(move |network_name| {
chain_stores
.clone()
.get(&network_name)
.ok_or(SubgraphRegistrarError::NetworkNotSupported(
network_name.clone(),
))
.and_then(move |chain_store| {
ethereum_adapters
.get(&network_name)
.ok_or(SubgraphRegistrarError::NetworkNotSupported(
network_name.clone(),
))
.map(move |ethereum_adapter| {
(
manifest,
ethereum_adapter.clone(),
chain_store.clone(),
)
})
})
})
})
.and_then(move |(manifest, ethereum_adapter, chain_store)| {
UnvalidatedSubgraphManifest::resolve(
hash.to_ipfs_link(),
self.resolver.clone(),
logger,
)
.map_err(SubgraphRegistrarError::ResolveError)
.and_then(move |unvalidated| {
future::result(unvalidated.validate(store_for_validation)).map_err(
|validation_errors| {
SubgraphRegistrarError::ManifestValidationError(validation_errors)
},
)
})
.and_then(move |(manifest, validation_warnings)| {
let network_name = manifest.network_name();
chain_stores
.clone()
.get(&network_name)
.ok_or(SubgraphRegistrarError::NetworkNotSupported(
network_name.clone(),
))
.and_then(move |chain_store| {
ethereum_adapters
.get(&network_name)
.ok_or(SubgraphRegistrarError::NetworkNotSupported(
network_name.clone(),
))
.map(move |ethereum_adapter| {
(
manifest,
ethereum_adapter.clone(),
chain_store.clone(),
validation_warnings,
)
})
})
})
.and_then(
move |(manifest, ethereum_adapter, chain_store, validation_warnings)| {
let manifest_id = manifest.id.clone();
create_subgraph_version(
&logger2,
store,
&logger_for_subgraph_version,
store_for_subgraph_version,
chain_store.clone(),
ethereum_adapter.clone(),
name,
manifest,
node_id,
version_switching_mode,
)
.map(|_| manifest_id)
})
.and_then(move |manifest_id| {
debug!(
logger3,
"Wrote new subgraph version to store";
"subgraph_name" => name_inner.to_string(),
"subgraph_hash" => manifest_id.to_string(),
);
Ok(())
}),
.map(|_| (manifest_id, validation_warnings))
},
)
.and_then(move |(manifest_id, validation_warnings)| {
debug!(
logger_for_debug,
"Wrote new subgraph version to store";
"subgraph_name" => name_inner.to_string(),
"subgraph_hash" => manifest_id.to_string(),
"validation_warnings" => format!("{:?}", validation_warnings),
);
Ok(())
}),
)
}

Expand Down
59 changes: 0 additions & 59 deletions core/src/subgraph/validation.rs

This file was deleted.

14 changes: 14 additions & 0 deletions graph/src/components/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use web3::types::H256;

use crate::data::schema::{SchemaImportError, SchemaReference};
use crate::data::store::*;
use crate::data::subgraph::schema::*;
use crate::prelude::*;
Expand Down Expand Up @@ -1187,6 +1188,19 @@ pub trait SubgraphDeploymentStore: Send + Sync + 'static {
/// store internals that should really be hidden and should be used
/// sparingly and only when absolutely needed
fn uses_relational_schema(&self, subgraph_id: &SubgraphDeploymentId) -> Result<bool, Error>;

fn resolve_schema_reference(
&self,
schema_reference: &SchemaReference,
) -> Result<Arc<Schema>, SchemaImportError>;

fn resolve_import_graph(
&self,
schema: &Schema,
) -> (
HashMap<SchemaReference, Arc<Schema>>,
Vec<SchemaImportError>,
);
}

/// Common trait for blockchain store implementations.
Expand Down
Loading