@@ -10,12 +10,13 @@ pub mod status;
1010
1111pub use features:: { SubgraphFeature , SubgraphFeatureValidationError } ;
1212
13+ use anyhow:: ensure;
1314use anyhow:: { anyhow, Error } ;
1415use futures03:: { future:: try_join3, stream:: FuturesOrdered , TryStreamExt as _} ;
1516use semver:: Version ;
1617use serde:: { de, ser} ;
1718use serde_yaml;
18- use slog:: { info, Logger } ;
19+ use slog:: { debug , info, Logger } ;
1920use stable_hash:: { FieldAddress , StableHash } ;
2021use stable_hash_legacy:: SequenceNumber ;
2122use std:: { collections:: BTreeSet , marker:: PhantomData } ;
@@ -24,7 +25,6 @@ use wasmparser;
2425use web3:: types:: Address ;
2526
2627use crate :: {
27- bail,
2828 blockchain:: { BlockPtr , Blockchain , DataSource as _} ,
2929 components:: {
3030 link_resolver:: LinkResolver ,
@@ -41,7 +41,6 @@ use crate::{
4141 offchain:: OFFCHAIN_KINDS , DataSource , DataSourceTemplate , UnresolvedDataSource ,
4242 UnresolvedDataSourceTemplate ,
4343 } ,
44- ensure,
4544 prelude:: { r, CheapClone , ENV_VARS } ,
4645} ;
4746
@@ -357,7 +356,7 @@ pub enum SubgraphManifestResolveError {
357356 #[ error( "subgraph is not valid YAML" ) ]
358357 InvalidFormat ,
359358 #[ error( "resolve error: {0}" ) ]
360- ResolveError ( # [ from ] anyhow:: Error ) ,
359+ ResolveError ( anyhow:: Error ) ,
361360}
362361
363362/// Data source contexts are conveniently represented as entities.
@@ -497,7 +496,7 @@ pub struct BaseSubgraphManifest<C, S, D, T> {
497496}
498497
499498/// SubgraphManifest with IPFS links unresolved
500- pub type UnresolvedSubgraphManifest < C > = BaseSubgraphManifest <
499+ type UnresolvedSubgraphManifest < C > = BaseSubgraphManifest <
501500 C ,
502501 UnresolvedSchema ,
503502 UnresolvedDataSource < C > ,
@@ -615,16 +614,35 @@ impl<C: Blockchain> SubgraphManifest<C> {
615614 /// Entry point for resolving a subgraph definition.
616615 pub async fn resolve_from_raw (
617616 id : DeploymentHash ,
618- raw : serde_yaml:: Mapping ,
617+ mut raw : serde_yaml:: Mapping ,
619618 resolver : & Arc < dyn LinkResolver > ,
620619 logger : & Logger ,
621620 max_spec_version : semver:: Version ,
622621 ) -> Result < Self , SubgraphManifestResolveError > {
623- let unresolved = UnresolvedSubgraphManifest :: parse ( id, raw) ?;
622+ // Inject the IPFS hash as the ID of the subgraph into the definition.
623+ raw. insert ( "id" . into ( ) , id. to_string ( ) . into ( ) ) ;
624+
625+ // Parse the YAML data into an UnresolvedSubgraphManifest
626+ let unresolved: UnresolvedSubgraphManifest < C > = serde_yaml:: from_value ( raw. into ( ) ) ?;
627+
628+ debug ! ( logger, "Features {:?}" , unresolved. features) ;
624629
625630 let resolved = unresolved
626631 . resolve ( resolver, logger, max_spec_version)
627- . await ?;
632+ . await
633+ . map_err ( SubgraphManifestResolveError :: ResolveError ) ?;
634+
635+ if ( resolved. spec_version < SPEC_VERSION_0_0_7 )
636+ && resolved
637+ . data_sources
638+ . iter ( )
639+ . any ( |ds| OFFCHAIN_KINDS . contains ( & ds. kind ( ) ) )
640+ {
641+ return Err ( SubgraphManifestResolveError :: ResolveError ( anyhow ! (
642+ "Offchain data sources not supported prior to {}" ,
643+ SPEC_VERSION_0_0_7
644+ ) ) ) ;
645+ }
628646
629647 Ok ( resolved)
630648 }
@@ -667,37 +685,15 @@ impl<C: Blockchain> SubgraphManifest<C> {
667685 ) -> Result < UnifiedMappingApiVersion , DifferentMappingApiVersions > {
668686 UnifiedMappingApiVersion :: try_from_versions ( self . api_versions ( ) )
669687 }
670-
671- pub fn template_idx_and_name ( & self ) -> impl Iterator < Item = ( u32 , String ) > + ' _ {
672- // We cannot include static data sources in the map because a static data source and a
673- // template may have the same name in the manifest. Duplicated with
674- // `UnresolvedSubgraphManifest::template_idx_and_name`.
675- let ds_len = self . data_sources . len ( ) as u32 ;
676- self . templates
677- . iter ( )
678- . map ( |t| t. name ( ) . to_owned ( ) )
679- . enumerate ( )
680- . map ( move |( idx, name) | ( ds_len + idx as u32 , name) )
681- }
682688}
683689
684690impl < C : Blockchain > UnresolvedSubgraphManifest < C > {
685- pub fn parse (
686- id : DeploymentHash ,
687- mut raw : serde_yaml:: Mapping ,
688- ) -> Result < Self , SubgraphManifestResolveError > {
689- // Inject the IPFS hash as the ID of the subgraph into the definition.
690- raw. insert ( "id" . into ( ) , id. to_string ( ) . into ( ) ) ;
691-
692- serde_yaml:: from_value ( raw. into ( ) ) . map_err ( Into :: into)
693- }
694-
695691 pub async fn resolve (
696692 self ,
697693 resolver : & Arc < dyn LinkResolver > ,
698694 logger : & Logger ,
699695 max_spec_version : semver:: Version ,
700- ) -> Result < SubgraphManifest < C > , SubgraphManifestResolveError > {
696+ ) -> Result < SubgraphManifest < C > , anyhow :: Error > {
701697 let UnresolvedSubgraphManifest {
702698 id,
703699 spec_version,
@@ -718,14 +714,14 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
718714 max_spec_version,
719715 id,
720716 spec_version
721- ) . into ( ) ) ;
717+ ) ) ;
722718 }
723719
724720 let ds_count = data_sources. len ( ) ;
725721 if ds_count as u64 + templates. len ( ) as u64 > u32:: MAX as u64 {
726- return Err (
727- anyhow ! ( "Subgraph has too many declared data sources and templates" , ) . into ( ) ,
728- ) ;
722+ return Err ( anyhow ! (
723+ "Subgraph has too many declared data sources and templates" ,
724+ ) ) ;
729725 }
730726
731727 let ( schema, data_sources, templates) = try_join3 (
@@ -758,17 +754,6 @@ impl<C: Blockchain> UnresolvedSubgraphManifest<C> {
758754 ) ;
759755 }
760756
761- if spec_version < SPEC_VERSION_0_0_7
762- && data_sources
763- . iter ( )
764- . any ( |ds| OFFCHAIN_KINDS . contains ( & ds. kind ( ) ) )
765- {
766- bail ! (
767- "Offchain data sources not supported prior to {}" ,
768- SPEC_VERSION_0_0_7
769- ) ;
770- }
771-
772757 Ok ( SubgraphManifest {
773758 id,
774759 spec_version,
0 commit comments