Skip to content

Commit 07b47f7

Browse files
committed
graph: Disallow nested subgraph datasources
1 parent 56bf046 commit 07b47f7

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

graph/src/data_source/subgraph.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,16 @@ impl UnresolvedDataSource {
287287
let source_manifest = self.resolve_source_manifest::<C>(resolver, logger).await?;
288288
let source_spec_version = &source_manifest.spec_version;
289289

290+
if source_manifest
291+
.data_sources
292+
.iter()
293+
.any(|ds| matches!(ds, crate::data_source::DataSource::Subgraph(_)))
294+
{
295+
return Err(anyhow!(
296+
"Nested subgraph data sources are not supported."
297+
));
298+
}
299+
290300
if source_spec_version < &SPEC_VERSION_1_3_0 {
291301
return Err(anyhow!(
292302
"Source subgraph manifest spec version {} is not supported, minimum supported version is {}",

store/test-store/tests/chain/ethereum/manifest.rs

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use graph::env::ENV_VARS;
2020
use graph::prelude::web3::types::H256;
2121
use graph::prelude::{
2222
anyhow, async_trait, serde_yaml, tokio, BigDecimal, BigInt, DeploymentHash, Link, Logger,
23-
SubgraphManifest, SubgraphManifestValidationError, SubgraphStore, UnvalidatedSubgraphManifest,
23+
SubgraphManifest, SubgraphManifestResolveError, SubgraphManifestValidationError, SubgraphStore,
24+
UnvalidatedSubgraphManifest,
2425
};
2526
use graph::{
2627
blockchain::NodeCapabilities as _,
@@ -1818,3 +1819,95 @@ specVersion: 1.3.0
18181819
.to_string()
18191820
.contains("Subgraph datasources cannot be used alongside onchain datasources"));
18201821
}
1822+
1823+
#[test]
1824+
fn nested_subgraph_ds_manifest_should_fail() {
1825+
let yaml = r#"
1826+
schema:
1827+
file:
1828+
/: /ipfs/Qmschema
1829+
dataSources:
1830+
- name: SubgraphSource
1831+
kind: subgraph
1832+
entities:
1833+
- User
1834+
network: mainnet
1835+
source:
1836+
address: 'QmNestedSource'
1837+
startBlock: 9562480
1838+
mapping:
1839+
apiVersion: 0.0.6
1840+
language: wasm/assemblyscript
1841+
entities:
1842+
- TestEntity
1843+
file:
1844+
/: /ipfs/Qmmapping
1845+
handlers:
1846+
- handler: handleEntity
1847+
entity: User
1848+
specVersion: 1.3.0
1849+
"#;
1850+
1851+
// First modify SOURCE_SUBGRAPH_MANIFEST to include a subgraph datasource
1852+
const NESTED_SOURCE_MANIFEST: &str = r#"
1853+
schema:
1854+
file:
1855+
/: /ipfs/QmSourceSchema
1856+
dataSources:
1857+
- kind: subgraph
1858+
name: NestedSource
1859+
network: mainnet
1860+
entities:
1861+
- User
1862+
source:
1863+
address: 'QmSource'
1864+
startBlock: 1
1865+
mapping:
1866+
apiVersion: 0.0.6
1867+
language: wasm/assemblyscript
1868+
entities:
1869+
- User
1870+
file:
1871+
/: /ipfs/Qmmapping
1872+
handlers:
1873+
- handler: handleNested
1874+
entity: User
1875+
specVersion: 1.3.0
1876+
"#;
1877+
1878+
let mut resolver = TextResolver::default();
1879+
let id = DeploymentHash::new("Qmmanifest").unwrap();
1880+
1881+
resolver.add(id.as_str(), &yaml);
1882+
resolver.add("/ipfs/Qmabi", &ABI);
1883+
resolver.add("/ipfs/Qmschema", &GQL_SCHEMA);
1884+
resolver.add("/ipfs/Qmmapping", &MAPPING_WITH_IPFS_FUNC_WASM);
1885+
resolver.add("/ipfs/QmNestedSource", &NESTED_SOURCE_MANIFEST);
1886+
resolver.add("/ipfs/QmSource", &SOURCE_SUBGRAPH_MANIFEST);
1887+
resolver.add("/ipfs/QmSourceSchema", &SOURCE_SUBGRAPH_SCHEMA);
1888+
1889+
let resolver: Arc<dyn LinkResolverTrait> = Arc::new(resolver);
1890+
1891+
let raw = serde_yaml::from_str(yaml).unwrap();
1892+
test_store::run_test_sequentially(|_| async move {
1893+
let result: Result<UnvalidatedSubgraphManifest<Chain>, _> =
1894+
UnvalidatedSubgraphManifest::resolve(
1895+
id,
1896+
raw,
1897+
&resolver,
1898+
&LOGGER,
1899+
SPEC_VERSION_1_3_0.clone(),
1900+
)
1901+
.await;
1902+
1903+
match result {
1904+
Ok(_) => panic!("Expected resolution to fail"),
1905+
Err(e) => {
1906+
assert!(matches!(e, SubgraphManifestResolveError::ResolveError(_)));
1907+
let error_msg = e.to_string();
1908+
println!("{}", error_msg);
1909+
assert!(error_msg.contains("Nested subgraph data sources are not supported."));
1910+
}
1911+
}
1912+
})
1913+
}

0 commit comments

Comments
 (0)