Repository: p2panda/aquadoggo (language: rust)

Issue:
Meta field `documentId` in GraphQL query returns nothing
`documentId` in `meta` returns nothing even though there is schemas registered. `viewId` works :+1:

```graphql
{
  all_schema_definition_v1 {
    meta {
      documentId
    }
    fields {
      name
    }
  }
}
```

Response:

```json
{
  "data": {
    "all_schema_definition_v1": [
      {
        "meta": {},
        "fields": {
          "name": "schema_name"
        }
      }
    ]
  }
}
```

Maybe its related to our recent change with the `DocumentId` scalar?!


Discussion / hints:
Aha, the problem comes from this method not receiving the `DocumentId` even when it was requested: https://github.com/p2panda/aquadoggo/blob/main/aquadoggo/src/graphql/client/dynamic_query.rs#L261

Guess its slightly related to this discussion https://github.com/p2panda/aquadoggo/issues/203?

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 44a6dff2b..4e59fa346 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Resolve implicit `__typename` field on dynamically generated GraphQL objects [#236](https://github.com/p2panda/aquadoggo/pull/236)
 - Allow `Content-Type` header [#236](https://github.com/p2panda/aquadoggo/pull/236)
 - Do not forget to register `DocumentIdScalar` [#252](https://github.com/p2panda/aquadoggo/pull/252)
+- Load `DocumentId` to be able to resolve it in meta field query [#258](https://github.com/p2panda/aquadoggo/pull/258)
 
 ## [0.3.0]
 
diff --git a/aquadoggo/src/graphql/client/dynamic_query.rs b/aquadoggo/src/graphql/client/dynamic_query.rs
index 54759a2a3..eb9303ed4 100644
--- a/aquadoggo/src/graphql/client/dynamic_query.rs
+++ b/aquadoggo/src/graphql/client/dynamic_query.rs
@@ -12,7 +12,7 @@ use log::{debug, error, info};
 use p2panda_rs::document::{DocumentId, DocumentView, DocumentViewId};
 use p2panda_rs::operation::OperationValue;
 use p2panda_rs::schema::SchemaId;
-use p2panda_rs::storage_provider::traits::DocumentStore;
+use p2panda_rs::storage_provider::traits::{DocumentStore, OperationStore};
 use p2panda_rs::Human;
 
 use crate::db::provider::SqlStorage;
@@ -53,6 +53,7 @@ impl ContainerType for DynamicQuery {
                 }
             }
         }
+
         // Continue by trying to parse it as a schema and, if that's successful, checking whether
         // this schema is available in the schema provider. If both are successfull, continue by
         // resolving this query as a query for a single document.
@@ -143,6 +144,7 @@ impl DynamicQuery {
             let selected_fields = ctx.field().selection_set().collect();
             self.document_response(view, ctx, selected_fields).await
         });
+
         Ok(Some(Value::List(
             future::try_join_all(documents_graphql_values).await?,
         )))
@@ -256,9 +258,15 @@ impl DynamicQuery {
                     document_fields.insert(response_key, Value::String(schema_id));
                 }
                 dynamic_types::document::META_FIELD => {
+                    let store = ctx.data_unchecked::<SqlStorage>();
+                    let document_id = store
+                        .get_document_by_operation_id(view.id().graph_tips().first().unwrap())
+                        .await
+                        .map_err(|err| ServerError::new(err.to_string(), None))?
+                        .unwrap();
                     document_fields.insert(
                         response_key,
-                        DocumentMeta::resolve(field, None, Some(view.id()))?,
+                        DocumentMeta::resolve(field, Some(&document_id), Some(view.id()))?,
                     );
                 }
                 dynamic_types::document::FIELDS_FIELD => {
diff --git a/aquadoggo/src/graphql/client/dynamic_types/document_meta.rs b/aquadoggo/src/graphql/client/dynamic_types/document_meta.rs
index c2bbbf2d9..ecaf5012f 100644
--- a/aquadoggo/src/graphql/client/dynamic_types/document_meta.rs
+++ b/aquadoggo/src/graphql/client/dynamic_types/document_meta.rs
@@ -25,6 +25,11 @@ impl DocumentMeta {
 
     /// Generate an object type for generic metadata and register it in a GraphQL schema registry.
     pub fn register_type(registry: &mut async_graphql::registry::Registry) {
+        // Important!
+        //
+        // Manually register scalar type in registry because it's not used in the static api.
+        DocumentIdScalar::create_type_info(registry);
+
         let mut fields = IndexMap::new();
 
         fields.insert(
@@ -36,9 +41,6 @@ impl DocumentMeta {
             ),
         );
 
-        // Manually register scalar type in registry because it's not used in the static api.
-        DocumentIdScalar::create_type_info(registry);
-
         fields.insert(
             VIEW_ID_FIELD.to_string(),
             metafield(


Test patch: