From 4e75a0865a0b7e1428bac83a2b0003309542994b Mon Sep 17 00:00:00 2001 From: Andreas Dzialocha Date: Fri, 2 Sep 2022 23:00:49 +0200 Subject: [PATCH 1/2] Load DocumentId to be able to resolve it in meta field --- aquadoggo/src/graphql/client/dynamic_query.rs | 12 ++++++++++-- .../graphql/client/dynamic_types/document_meta.rs | 8 +++++--- 2 files changed, 15 insertions(+), 5 deletions(-) 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::(); + 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( From 3c53b1da31060abedc4112ff227938937ce38bc0 Mon Sep 17 00:00:00 2001 From: Andreas Dzialocha Date: Fri, 2 Sep 2022 23:03:06 +0200 Subject: [PATCH 2/2] Add entry to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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]