Skip to content

Commit 47a4a10

Browse files
committed
graphql: Add subgraphError argument only when feature is present
We saw an issue in a graphql client that is avoided by doing this. and it is generally more correct to only include it if the subgraph opts in. This requires storing the `features` field in the metadata, which we should be doing anyways.
1 parent ce52896 commit 47a4a10

File tree

12 files changed

+198
-85
lines changed

12 files changed

+198
-85
lines changed

graph/src/data/subgraph/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,3 +1305,22 @@ impl DeploymentState {
13051305
pub enum SubgraphFeature {
13061306
nonFatalErrors,
13071307
}
1308+
1309+
impl std::fmt::Display for SubgraphFeature {
1310+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1311+
match self {
1312+
SubgraphFeature::nonFatalErrors => write!(f, "nonFatalErrors"),
1313+
}
1314+
}
1315+
}
1316+
1317+
impl FromStr for SubgraphFeature {
1318+
type Err = anyhow::Error;
1319+
1320+
fn from_str(s: &str) -> anyhow::Result<Self> {
1321+
match s {
1322+
"nonFatalErrors" => Ok(SubgraphFeature::nonFatalErrors),
1323+
_ => Err(anyhow::anyhow!("invalid subgraph feature {}", s)),
1324+
}
1325+
}
1326+
}

graph/src/data/subgraph/schema.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ pub struct SubgraphManifestEntity {
438438
spec_version: String,
439439
description: Option<String>,
440440
repository: Option<String>,
441+
features: Vec<String>,
441442
schema: String,
442443
data_sources: Vec<EthereumContractDataSourceEntity>,
443444
templates: Vec<EthereumContractDataSourceTemplateEntity>,
@@ -454,17 +455,26 @@ impl SubgraphManifestEntity {
454455
}
455456

456457
fn write_operations(self, id: &str) -> Vec<MetadataOperation> {
458+
let SubgraphManifestEntity {
459+
spec_version,
460+
description,
461+
repository,
462+
features,
463+
schema,
464+
data_sources,
465+
templates,
466+
} = self;
467+
457468
let mut ops = vec![];
458469

459470
let mut data_source_ids: Vec<Value> = vec![];
460-
for (i, data_source) in self.data_sources.into_iter().enumerate() {
471+
for (i, data_source) in data_sources.into_iter().enumerate() {
461472
let data_source_id = format!("{}-data-source-{}", id, i);
462473
ops.extend(data_source.write_operations(&data_source_id));
463474
data_source_ids.push(data_source_id.into());
464475
}
465476

466-
let template_ids: Vec<Value> = self
467-
.templates
477+
let template_ids: Vec<Value> = templates
468478
.into_iter()
469479
.enumerate()
470480
.map(|(i, template)| {
@@ -476,10 +486,11 @@ impl SubgraphManifestEntity {
476486

477487
let entity = entity! {
478488
id: id,
479-
specVersion: self.spec_version,
480-
description: self.description,
481-
repository: self.repository,
482-
schema: self.schema,
489+
specVersion: spec_version,
490+
description: description,
491+
repository: repository,
492+
features: features,
493+
schema: schema,
483494
dataSources: data_source_ids,
484495
templates: template_ids,
485496
};
@@ -496,6 +507,7 @@ impl<'a> From<&'a super::SubgraphManifest> for SubgraphManifestEntity {
496507
spec_version: manifest.spec_version.clone(),
497508
description: manifest.description.clone(),
498509
repository: manifest.repository.clone(),
510+
features: manifest.features.iter().map(|f| f.to_string()).collect(),
499511
schema: manifest.schema.document.clone().to_string(),
500512
data_sources: manifest.data_sources.iter().map(Into::into).collect(),
501513
templates: manifest

graphql/examples/schema.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use graphql_parser::parse_schema;
2-
use std::env;
32
use std::fs;
43
use std::process::exit;
4+
use std::{collections::BTreeSet, env};
55

66
use graph_graphql::schema::api::api_schema;
77

@@ -31,7 +31,10 @@ pub fn main() {
3131
};
3232
let schema = ensure(fs::read_to_string(schema), "Can not read schema file");
3333
let schema = ensure(parse_schema(&schema), "Failed to parse schema");
34-
let schema = ensure(api_schema(&schema), "Failed to convert to API schema");
34+
let schema = ensure(
35+
api_schema(&schema, &BTreeSet::new()),
36+
"Failed to convert to API schema",
37+
);
3538

3639
println!("{}", schema);
3740
}

0 commit comments

Comments
 (0)