This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch CAUSEWAY-3676
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit d724ffdd56a9249fcc9383f4939761a7c25a6906
Author: danhaywood <[email protected]>
AuthorDate: Tue Feb 13 00:09:17 2024 +0000

    CAUSEWAY-3676: factors out GqlvMetaVersion; also SaveAs
---
 .../viewer/graphql/model/domain/GqlvMeta.java      | 24 +++++-----
 .../graphql/model/domain/GqlvMetaSaveAs.java       | 56 ++++++++++++++++++++++
 .../graphql/model/domain/GqlvMetaVersion.java      | 42 ++++++++++++++++
 .../viewer/graphql/model/domain/GqlvScenario.java  | 19 ++++----
 ...IntegTest.find_department_and_change_name._.gql |  4 +-
 viewers/graphql/test/src/test/resources/schema.gql | 37 ++++++++++++++
 6 files changed, 161 insertions(+), 21 deletions(-)

diff --git 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
index 5a062264c1..8b51c01f2c 100644
--- 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
+++ 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java
@@ -44,18 +44,17 @@ import lombok.val;
 
 public class GqlvMeta extends GqlvAbstractCustom {
 
-    static GraphQLFieldDefinition version = 
newFieldDefinition().name("version").type(Scalars.GraphQLString).build();
-
+    private final Holder holder;
     private final GqlvMetaId metaId;
     private final GqlvMetaLogicalTypeName metaLogicalTypeName;
-    private final Holder holder;
+    private final GqlvMetaVersion metaVersion;
+    private final GqlvMetaSaveAs metaSaveAs;
 
     public GqlvMeta(
             final Holder holder,
             final Context context
     ) {
         super(TypeNames.metaTypeNameFor(holder.getObjectSpecification()), 
context);
-
         this.holder = holder;
 
         metaId = new GqlvMetaId(context);
@@ -64,10 +63,16 @@ public class GqlvMeta extends GqlvAbstractCustom {
         metaLogicalTypeName = new GqlvMetaLogicalTypeName(context);
         addChildField(metaLogicalTypeName.getField());
 
-        if (this.holder.getObjectSpecification().getBeanSort() == 
BeanSort.ENTITY) {
-            addChildField(version);
+        if (holder.getObjectSpecification().getBeanSort() == BeanSort.ENTITY) {
+            metaVersion = new GqlvMetaVersion(context);
+            addChildField(metaVersion.getField());
+        } else {
+            metaVersion = null;
         }
 
+        metaSaveAs = new GqlvMetaSaveAs(context);
+        addChildField(metaSaveAs.getField());
+
         val fieldName = 
context.causewayConfiguration.getViewer().getGraphql().getMetaData().getFieldName();
         buildObjectTypeAndField(fieldName);
     }
@@ -76,12 +81,10 @@ public class GqlvMeta extends GqlvAbstractCustom {
     protected void addDataFetchersForChildren() {
         metaId.addDataFetcher(this);
         metaLogicalTypeName.addDataFetcher(this);
-
         if (holder.getObjectSpecification().getBeanSort() == BeanSort.ENTITY) {
-            context.codeRegistryBuilder.dataFetcher(
-                    coordinates(getGqlObjectType(), version),
-                    (DataFetcher<Object>) environment -> 
environment.<Fetcher>getSource().version());
+            metaVersion.addDataFetcher(this);
         }
+        metaSaveAs.addDataFetcher(this);
     }
 
     @Override
@@ -92,7 +95,6 @@ public class GqlvMeta extends GqlvAbstractCustom {
     }
 
 
-
     /**
      * Metadata for every domain object.
      */
diff --git 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaSaveAs.java
 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaSaveAs.java
new file mode 100644
index 0000000000..c095689b01
--- /dev/null
+++ 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaSaveAs.java
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.causeway.viewer.graphql.model.domain;
+
+import graphql.Scalars;
+import graphql.schema.DataFetchingEnvironment;
+import graphql.schema.GraphQLArgument;
+
+import org.apache.causeway.viewer.graphql.model.context.Context;
+import org.apache.causeway.viewer.graphql.model.fetcher.BookmarkedPojo;
+
+import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
+
+public class GqlvMetaSaveAs extends GqlvAbstract {
+
+    public GqlvMetaSaveAs(final Context context) {
+        super(context);
+
+        setField(newFieldDefinition()
+                    .name("saveAs")
+                    .type(Scalars.GraphQLString)
+                    .argument(new GraphQLArgument.Builder()
+                            .name("ref")
+                            .type(Scalars.GraphQLString)
+                    )
+                    .build());
+    }
+
+    @Override
+    protected Object fetchData(DataFetchingEnvironment environment) {
+        String ref = environment.getArgument("ref");
+        environment.getGraphQlContext().put(keyFor(ref), 
BookmarkedPojo.sourceFrom(environment));
+        return ref;
+    }
+
+    private static String keyFor(String ref) {
+        return GqlvMetaSaveAs.class.getName() + "#" + ref;
+    }
+
+}
diff --git 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaVersion.java
 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaVersion.java
new file mode 100644
index 0000000000..efa5cf9000
--- /dev/null
+++ 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMetaVersion.java
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.causeway.viewer.graphql.model.domain;
+
+import graphql.Scalars;
+import graphql.schema.DataFetchingEnvironment;
+
+import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
+import static graphql.schema.GraphQLNonNull.nonNull;
+
+import org.apache.causeway.viewer.graphql.model.context.Context;
+
+public class GqlvMetaVersion extends GqlvAbstract {
+
+    public GqlvMetaVersion(final Context context) {
+        super(context);
+
+        
setField(newFieldDefinition().name("version").type(Scalars.GraphQLString).build());
+    }
+
+    @Override
+    protected String fetchData(DataFetchingEnvironment environment) {
+        return environment.<GqlvMeta.Fetcher>getSource().version();
+    }
+
+}
diff --git 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvScenario.java
 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvScenario.java
index 10240f86ab..ea9f7c75b2 100644
--- 
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvScenario.java
+++ 
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvScenario.java
@@ -19,12 +19,15 @@
 package org.apache.causeway.viewer.graphql.model.domain;
 
 import graphql.Scalars;
+import graphql.language.FieldDefinition;
 import graphql.schema.DataFetchingEnvironment;
 import graphql.schema.GraphQLArgument;
 import graphql.schema.GraphQLFieldDefinition;
 
 import org.apache.causeway.viewer.graphql.model.context.Context;
 
+import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
+
 /**
  * Exposes a domain service (view model or entity) via the GQL viewer.
  */
@@ -50,14 +53,14 @@ public class GqlvScenario
 
         buildObjectType();
 
-        setField(new GraphQLFieldDefinition.Builder()
-                            .name("Scenario")
-                            .type(getGqlObjectType())
-                            .argument(new GraphQLArgument.Builder()
-                                                .name("name")
-                                                .type(Scalars.GraphQLString)
-                            )
-                            .build()
+        setField(newFieldDefinition()
+                    .name("Scenario")
+                    .type(getGqlObjectType())
+                    .argument(new GraphQLArgument.Builder()
+                                        .name("name")
+                                        .type(Scalars.GraphQLString)
+                    )
+                    .build()
         );
     }
 
diff --git 
a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Department_IntegTest.find_department_and_change_name._.gql
 
b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Department_IntegTest.find_department_and_change_name._.gql
index e143491e46..5bb0283dd3 100644
--- 
a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Department_IntegTest.find_department_and_change_name._.gql
+++ 
b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/scenario/Department_IntegTest.find_department_and_change_name._.gql
@@ -5,8 +5,8 @@
       university_dept_Departments {
         findDepartmentByName {
           invoke(name: "Classics") {
-            name {
-              get
+            _gqlv_meta {
+              saveAs(ref: "classics_dept")
             }
           }
         }
diff --git a/viewers/graphql/test/src/test/resources/schema.gql 
b/viewers/graphql/test/src/test/resources/schema.gql
index 5bef2dd3be..8920b0eae9 100644
--- a/viewers/graphql/test/src/test/resources/schema.gql
+++ b/viewers/graphql/test/src/test/resources/schema.gql
@@ -171,6 +171,7 @@ type 
causeway_applib_DomainObjectList__elementTypeFqcn__gqlv_property {
 type causeway_applib_DomainObjectList__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_DomainObjectList__objects__gqlv_collection {
@@ -209,6 +210,7 @@ type causeway_applib_FacetGroupNode__facets__gqlv_property {
 type causeway_applib_FacetGroupNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_FacetGroupNode__parentNode__gqlv_property {
@@ -233,6 +235,7 @@ type 
causeway_applib_ParameterNode__childNodes__gqlv_collection {
 type causeway_applib_ParameterNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_ParameterNode__parameter__gqlv_property {
@@ -267,6 +270,7 @@ type 
causeway_applib_PropertyNode__childNodes__gqlv_collection {
 type causeway_applib_PropertyNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_PropertyNode__mixedIn__gqlv_property {
@@ -310,6 +314,7 @@ type 
causeway_applib_RoleMemento__description__gqlv_property {
 type causeway_applib_RoleMemento__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_RoleMemento__name__gqlv_property {
@@ -343,6 +348,7 @@ type 
causeway_applib_TypeNode__domainClassDto__gqlv_property {
 type causeway_applib_TypeNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_TypeNode__parentNode__gqlv_property {
@@ -395,6 +401,7 @@ type causeway_applib_UserMemento__avatarUrl__gqlv_property {
 type causeway_applib_UserMemento__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_UserMemento__impersonating__gqlv_property {
@@ -494,6 +501,7 @@ type 
causeway_applib_node_ActionNode__childNodes__gqlv_collection {
 type causeway_applib_node_ActionNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_node_ActionNode__mixedIn__gqlv_property {
@@ -536,6 +544,7 @@ type 
causeway_applib_node_CollectionNode__collection__gqlv_property {
 type causeway_applib_node_CollectionNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_node_CollectionNode__mixedIn__gqlv_property {
@@ -577,6 +586,7 @@ type 
causeway_applib_node_FacetAttrNode__facetAttr__gqlv_property {
 type causeway_applib_node_FacetAttrNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_node_FacetAttrNode__parentNode__gqlv_property {
@@ -611,6 +621,7 @@ type causeway_applib_node_FacetNode__facet__gqlv_property {
 type causeway_applib_node_FacetNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_applib_node_FacetNode__parentNode__gqlv_property {
@@ -648,6 +659,7 @@ type causeway_conf_ConfigurationProperty {
 type causeway_conf_ConfigurationProperty__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_conf_ConfigurationProperty__key__gqlv_property {
@@ -682,6 +694,7 @@ type 
causeway_conf_ConfigurationViewmodel__environment__gqlv_collection {
 type causeway_conf_ConfigurationViewmodel__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_conf_ConfigurationViewmodel__primary__gqlv_collection {
@@ -707,6 +720,7 @@ type causeway_feat_ApplicationFeatureViewModel {
 type causeway_feat_ApplicationFeatureViewModel__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationFeatureViewModel__memberName__gqlv_property {
@@ -757,6 +771,7 @@ type 
causeway_feat_ApplicationNamespace__contents__gqlv_collection {
 type causeway_feat_ApplicationNamespace__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationNamespace__memberName__gqlv_property {
@@ -823,6 +838,7 @@ type 
causeway_feat_ApplicationTypeAction__actionSemantics__gqlv_property {
 type causeway_feat_ApplicationTypeAction__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationTypeAction__memberName__gqlv_property {
@@ -893,6 +909,7 @@ type 
causeway_feat_ApplicationTypeCollection__elementType__gqlv_property {
 type causeway_feat_ApplicationTypeCollection__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationTypeCollection__memberName__gqlv_property {
@@ -937,6 +954,7 @@ type causeway_feat_ApplicationTypeMember {
 type causeway_feat_ApplicationTypeMember__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationTypeMember__memberName__gqlv_property {
@@ -993,6 +1011,7 @@ type 
causeway_feat_ApplicationTypeProperty__derived__gqlv_property {
 type causeway_feat_ApplicationTypeProperty__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationTypeProperty__maxLength__gqlv_property {
@@ -1065,6 +1084,7 @@ type 
causeway_feat_ApplicationType__collections__gqlv_collection {
 type causeway_feat_ApplicationType__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_feat_ApplicationType__memberName__gqlv_property {
@@ -1152,6 +1172,7 @@ type 
causeway_schema_metamodel_v2_DomainClassDto__facets__gqlv_property {
 type causeway_schema_metamodel_v2_DomainClassDto__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_schema_metamodel_v2_DomainClassDto__id__gqlv_property {
@@ -1201,6 +1222,7 @@ type causeway_security_LoginRedirect {
 type causeway_security_LoginRedirect__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_security_LogoutMenu {
@@ -1241,6 +1263,7 @@ type 
causeway_testing_fixtures_FixtureResult__fixtureScriptClassName__gqlv_prope
 type causeway_testing_fixtures_FixtureResult__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type causeway_testing_fixtures_FixtureResult__key__gqlv_property {
@@ -1265,6 +1288,7 @@ type java_lang_Runnable {
 type java_lang_Runnable__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_Map {
@@ -1274,6 +1298,7 @@ type java_util_Map {
 type java_util_Map__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_SortedMap {
@@ -1283,6 +1308,7 @@ type java_util_SortedMap {
 type java_util_SortedMap__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_concurrent_Callable {
@@ -1292,6 +1318,7 @@ type java_util_concurrent_Callable {
 type java_util_concurrent_Callable__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_function_BiFunction {
@@ -1301,6 +1328,7 @@ type java_util_function_BiFunction {
 type java_util_function_BiFunction__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_function_Consumer {
@@ -1310,6 +1338,7 @@ type java_util_function_Consumer {
 type java_util_function_Consumer__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_function_Function {
@@ -1319,6 +1348,7 @@ type java_util_function_Function {
 type java_util_function_Function__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type java_util_stream_Stream {
@@ -1328,6 +1358,7 @@ type java_util_stream_Stream {
 type java_util_stream_Stream__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type org_apache_causeway_core_metamodel_inspect_model_MMNode {
@@ -1344,6 +1375,7 @@ type 
org_apache_causeway_core_metamodel_inspect_model_MMNode__childNodes__gqlv_c
 type org_apache_causeway_core_metamodel_inspect_model_MMNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type 
org_apache_causeway_core_metamodel_inspect_model_MMNode__parentNode__gqlv_property
 {
@@ -1368,6 +1400,7 @@ type 
org_apache_causeway_core_metamodel_inspect_model_MemberNode__childNodes__gq
 type org_apache_causeway_core_metamodel_inspect_model_MemberNode__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type 
org_apache_causeway_core_metamodel_inspect_model_MemberNode__mixedIn__gqlv_property
 {
@@ -1403,6 +1436,7 @@ type 
org_apache_causeway_testing_fixtures_applib_fixturescripts_FixtureScript__f
 type 
org_apache_causeway_testing_fixtures_applib_fixturescripts_FixtureScript__gqlv_meta
 {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
 }
 
 type 
org_apache_causeway_testing_fixtures_applib_fixturescripts_FixtureScript__qualifiedName__gqlv_property
 {
@@ -2076,6 +2110,7 @@ type university_dept_Department__deptHead__gqlv_property {
 type university_dept_Department__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
   version: String
 }
 
@@ -2227,6 +2262,7 @@ type university_dept_DeptHead__department__gqlv_property {
 type university_dept_DeptHead__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
   version: String
 }
 
@@ -2294,6 +2330,7 @@ type 
university_dept_StaffMember__department__gqlv_property {
 type university_dept_StaffMember__gqlv_meta {
   id: String!
   logicalTypeName: String!
+  saveAs(ref: String): String
   version: String
 }
 

Reply via email to