runtime/wasm: Automatically add __typename to entities in store.get()
@@ -99,6 +99,7 @@ where
id: String,
mut data: HashMap<String, Value>,
) -> Result<(), HostExportError<impl ExportError>> {
+ // Automatically add an "id" value
match data.insert("id".to_string(), Value::String(id.clone())) {
Some(ref v) if v != &Value::String(id.clone()) => {
return Err(HostExportError(format!(
@@ -109,6 +110,17 @@ where
_ => (),
}
+ // Automatically add a "__typename" value
+ match data.insert("__typename".to_string(), Value::String(entity.clone())) {
+ Some(ref v) if v != &Value::String(entity.clone()) => {
+ return Err(HostExportError(format!(
+ "Conflicting '__typename' value set by mapping for {} entity: {} != {}",
+ entity, v, entity
+ )))
+ }
+ _ => (),
+ }
+
self.ctx
.as_mut()
.map(|ctx| &mut ctx.entity_operations)
