You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2024/01/26 13:07:37 UTC

(causeway) branch CAUSEWAY-3676 updated (7e206efb32 -> 42580678d8)

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

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


    from 7e206efb32 CAUSEWAY-3676: adds addStaffMembers to test domain
     new 1516452439 CAUSEWAY-3676: wip, adding support for collection params
     new 07c3e1f08b CAUSEWAY-3676: wip, adding support for collection params (2)
     new 42580678d8 CAUSEWAY-3676: adds support for collection params

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../viewer/graphql/model/domain/GqlvAction.java    |  74 ++++++--
 .../graphql/model/domain/GqlvDomainObject.java     |   2 +-
 .../viewer/graphql/model/types/TypeMapper.java     |  27 ++-
 ...ayViewerGraphqlTestModuleIntegTestAbstract.java |   9 +
 .../graphql/viewer/test/domain/Department.java     |   3 +-
 ...department_and_add_staff_members._.choices.gql} |   7 +-
 ..._department_and_add_staff_members._.invoke.gql} |  11 +-
 ..._department_and_add_staff_members.approved.json |  36 ++++
 .../graphql/viewer/test/e2e/Domain_IntegTest.java  |  37 +++-
 .../test/e2e/Schema_IntegTest.schema.approved.json | 204 +++++++++++++++++++++
 ...chema_IntegTest.schema_types_name.approved.json |   6 +
 .../src/test/resources/application-test.properties |   2 +-
 .../graphql/test/src/test/resources/schema.gql     |  20 ++
 13 files changed, 413 insertions(+), 25 deletions(-)
 copy incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/{Domain_IntegTest.find_department_and_remove_staff_member_choices._.gql => Domain_IntegTest.find_department_and_add_staff_members._.choices.gql} (68%)
 copy incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/{Domain_IntegTest.find_department_and_change_head_default._.gql => Domain_IntegTest.find_department_and_add_staff_members._.invoke.gql} (50%)
 create mode 100644 incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members.approved.json


(causeway) 03/03: CAUSEWAY-3676: adds support for collection params

Posted by da...@apache.org.
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 42580678d8da23e54fcaff1e21774fe12bf58477
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jan 26 13:06:06 2024 +0000

    CAUSEWAY-3676: adds support for collection params
---
 .../viewer/graphql/model/domain/GqlvAction.java    | 50 +++++++++++++++++-----
 ...ayViewerGraphqlTestModuleIntegTestAbstract.java |  9 ++++
 .../graphql/viewer/test/domain/Department.java     |  3 +-
 ..._department_and_add_staff_members._.choices.gql | 22 ++++++++++
 ...d_department_and_add_staff_members._.invoke.gql | 22 ++++++++++
 ..._department_and_add_staff_members.approved.json | 36 ++++++++++++++++
 .../graphql/viewer/test/e2e/Domain_IntegTest.java  | 37 +++++++++++++++-
 7 files changed, 167 insertions(+), 12 deletions(-)

diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
index e99ac54172..04bf02b77b 100644
--- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
+++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
@@ -36,7 +36,9 @@ import graphql.schema.*;
 import lombok.extern.log4j.Log4j2;
 import lombok.val;
 
+import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -101,23 +103,26 @@ public class GqlvAction
                     switch (elementType.getBeanSort()) {
 
                         case VALUE:
+                            // TODO: handle lists of values.
                             return ManagedObject.adaptParameter(oap, argumentValue);
 
                         case ENTITY:
                         case VIEW_MODEL:
-                            //noinspection unchecked
                             if (argumentValue == null) {
                                 return ManagedObject.empty(elementType);
                             }
-                            String idValue = ((Map<String, String>) argumentValue).get("id");
-                            Class<?> paramClass = elementType.getCorrespondingClass();
-                            Optional<Bookmark> bookmarkIfAny = bookmarkService.bookmarkFor(paramClass, idValue);
-                            return bookmarkIfAny
-                                    .map(bookmarkService::lookup)
-                                    .filter(Optional::isPresent)
-                                    .map(Optional::get)
-                                    .map(pojo -> ManagedObject.adaptParameter(oap, pojo))
-                                    .orElse(ManagedObject.empty(elementType));
+                            Object pojoOrPojoList;
+                            if (argumentValue instanceof List) {
+                                val argumentValueList = (List<Object>) argumentValue;
+                                pojoOrPojoList = argumentValueList.stream()
+                                        .map(value -> asPojo(oap.getElementType(), value, bookmarkService))
+                                        .filter(Optional::isPresent)
+                                        .map(Optional::get)
+                                        .collect(Collectors.toList());
+                            } else {
+                                pojoOrPojoList = asPojo(oap.getElementType(), argumentValue, bookmarkService).orElse(null);
+                            }
+                            return ManagedObject.adaptParameter(oap, pojoOrPojoList);
 
                         case ABSTRACT:
                         case COLLECTION:
@@ -133,6 +138,31 @@ public class GqlvAction
                 });
     }
 
+    private static ManagedObject asDomainObject(
+            final ObjectSpecification elementType,
+            final ObjectActionParameter oap,
+            final Object argumentValueObj,
+            final BookmarkService bookmarkService) {
+        return asPojo(elementType, argumentValueObj, bookmarkService)
+                .map(pojo -> ManagedObject.adaptParameter(oap, pojo))
+                .orElse(ManagedObject.empty(elementType));
+    }
+
+    private static Optional<Object> asPojo(
+            final ObjectSpecification elementType,
+            final Object argumentValueObj,
+            final BookmarkService bookmarkService) {
+        val argumentValue = (Map<String, String>) argumentValueObj;
+        String idValue = argumentValue.get("id");
+        Class<?> paramClass = elementType.getCorrespondingClass();
+        Optional<Bookmark> bookmarkIfAny = bookmarkService.bookmarkFor(paramClass, idValue);
+        return bookmarkIfAny
+                .map(bookmarkService::lookup)
+                .filter(Optional::isPresent)
+                .map(Optional::get)
+;
+    }
+
     static void addGqlArguments(
             final ObjectAction objectAction,
             final GraphQLFieldDefinition.Builder builder,
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/CausewayViewerGraphqlTestModuleIntegTestAbstract.java b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/CausewayViewerGraphqlTestModuleIntegTestAbstract.java
index 1496364764..7e40dae0ae 100644
--- a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/CausewayViewerGraphqlTestModuleIntegTestAbstract.java
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/CausewayViewerGraphqlTestModuleIntegTestAbstract.java
@@ -165,6 +165,15 @@ public abstract class CausewayViewerGraphqlTestModuleIntegTestAbstract {
         return submitRequest(httpRequest);
     }
 
+    protected String submit(String variant) throws Exception{
+        return submit(variant, Collections.emptyMap());
+    }
+
+    protected String submit(String variant, Map<String,String> replacements) throws Exception{
+        val httpRequest = buildRequest(testInfo, "._." +variant + ".gql", replacements);
+        return submitRequest(httpRequest);
+    }
+
     @Value
     protected static class GqlBody {
         String query;
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/Department.java b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/Department.java
index d03c2b99e2..aa1275350e 100644
--- a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/Department.java
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/Department.java
@@ -161,8 +161,9 @@ public class Department implements Comparable<Department> {
         public Department act(List<StaffMember> staffMembers) {
             val department = Department.this;
 
-            department.staffMembers.addAll(staffMembers);
             staffMembers.forEach(sm -> sm.setDepartment(department));
+            department.staffMembers.addAll(staffMembers);
+
             return department;
         }
         public List<StaffMember> choices0Act() {
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.choices.gql b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.choices.gql
new file mode 100644
index 0000000000..ca9a1d7785
--- /dev/null
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.choices.gql
@@ -0,0 +1,22 @@
+{
+  university_dept_Departments {
+    findByName {
+      invoke(name: "Classics") {
+        addStaffMembers {
+          params {
+            staffMembers {
+              choices {
+                _gql_meta {
+                  id
+                }
+                name {
+                  get
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.invoke.gql b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.invoke.gql
new file mode 100644
index 0000000000..899406964d
--- /dev/null
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members._.invoke.gql
@@ -0,0 +1,22 @@
+{
+  university_dept_Departments {
+    findByName {
+      invoke(name: "Classics") {
+        addStaffMembers {
+          invokeIdempotent(staffMembers: [{id: "$staffMemberId1"}, {id: "$staffMemberId2"}]) {
+            name {
+              get
+            }
+            staffMembers {
+              get {
+                name {
+                  get
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members.approved.json b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members.approved.json
new file mode 100644
index 0000000000..a2fa305574
--- /dev/null
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.find_department_and_add_staff_members.approved.json
@@ -0,0 +1,36 @@
+{
+  "data" : {
+    "university_dept_Departments" : {
+      "findByName" : {
+        "invoke" : {
+          "addStaffMembers" : {
+            "invokeIdempotent" : {
+              "name" : {
+                "get" : "Classics"
+              },
+              "staffMembers" : {
+                "get" : [ {
+                  "name" : {
+                    "get" : "Gerry Jones"
+                  }
+                }, {
+                  "name" : {
+                    "get" : "John Gartner"
+                  }
+                }, {
+                  "name" : {
+                    "get" : "Letitia Leadbetter"
+                  }
+                }, {
+                  "name" : {
+                    "get" : "Mervin Hughes"
+                  }
+                } ]
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
index 4bb2648632..bf73968c5f 100644
--- a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Domain_IntegTest.java
@@ -20,13 +20,16 @@ package org.apache.causeway.viewer.graphql.viewer.test.e2e;
 
 import lombok.val;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 
 import javax.inject.Inject;
 
 import org.apache.causeway.applib.services.bookmark.Bookmark;
 import org.apache.causeway.applib.services.bookmark.BookmarkService;
+import org.apache.causeway.commons.internal.base._Strings;
 import org.apache.causeway.commons.internal.collections._Maps;
 import org.apache.causeway.viewer.graphql.viewer.test.domain.StaffMember;
 import org.apache.causeway.viewer.graphql.viewer.test.domain.StaffMemberRepository;
@@ -50,6 +53,9 @@ import org.apache.causeway.viewer.graphql.viewer.test.domain.DepartmentRepositor
 import org.apache.causeway.viewer.graphql.viewer.test.domain.DeptHead;
 import org.apache.causeway.viewer.graphql.viewer.test.domain.DeptHeadRepository;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 import static org.apache.causeway.commons.internal.assertions._Assert.assertEquals;
 import static org.apache.causeway.commons.internal.assertions._Assert.assertTrue;
 
@@ -86,7 +92,7 @@ public class Domain_IntegTest extends CausewayViewerGraphqlTestModuleIntegTestAb
             staffMemberRepository.create("Letitia Leadbetter", classics);
             staffMemberRepository.create("Gerry Jones", classics);
             staffMemberRepository.create("Mervin Hughes", physics);
-            staffMemberRepository.create("John Gaffney", physics);
+            staffMemberRepository.create("John Gartner", physics);
             staffMemberRepository.create("Margaret Randall", physics);
 
         });
@@ -173,6 +179,35 @@ public class Domain_IntegTest extends CausewayViewerGraphqlTestModuleIntegTestAb
         Approvals.verify(submit(), jsonOptions());
     }
 
+    @Test
+    @UseReporter(DiffReporter.class)
+    void find_department_and_add_staff_members() throws Exception {
+
+        // when, then
+        String submit = submit("choices");
+
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode root = mapper.readTree(submit);
+
+        JsonNode staffMembersNode = root.at("/data/university_dept_Departments/findByName/invoke/addStaffMembers/params/staffMembers/choices");
+
+        List<String> ids = new ArrayList<>();
+        staffMembersNode.forEach(staffMemberNode -> {
+            String id = staffMemberNode.get("_gql_meta").get("id").asText();
+            if (!_Strings.isNullOrEmpty(id)) {
+                ids.add(id);
+            }
+        });
+
+        Assertions.assertThat(ids).hasSize(3);
+
+        val replacements = _Maps.unmodifiable(
+                                "$staffMemberId1", ids.get(0),
+                                "$staffMemberId2", ids.get(1));
+
+        Approvals.verify(submit("invoke", replacements), jsonOptions());
+    }
+
     @Test
     @UseReporter(DiffReporter.class)
     void find_staff_member_by_name_and_edit() throws Exception {


(causeway) 02/03: CAUSEWAY-3676: wip, adding support for collection params (2)

Posted by da...@apache.org.
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 07c3e1f08bb0fe1bfc8a1bbc0eb90cd58a287e5f
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jan 26 10:31:32 2024 +0000

    CAUSEWAY-3676: wip, adding support for collection params (2)
---
 .../test/e2e/Schema_IntegTest.schema.approved.json | 204 +++++++++++++++++++++
 ...chema_IntegTest.schema_types_name.approved.json |   6 +
 2 files changed, 210 insertions(+)

diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema.approved.json b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema.approved.json
index 2d2e02c5c7..ba85c2457f 100644
--- a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema.approved.json
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema.approved.json
@@ -22726,6 +22726,17 @@
           },
           "isDeprecated" : false,
           "deprecationReason" : null
+        }, {
+          "name" : "addStaffMembers",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "OBJECT",
+            "name" : "university_dept_Department__addStaffMembers__gqlv_action",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
         }, {
           "name" : "removeStaffMember",
           "description" : null,
@@ -22936,6 +22947,199 @@
         "interfaces" : [ ],
         "enumValues" : null,
         "possibleTypes" : null
+      }, {
+        "kind" : "OBJECT",
+        "name" : "university_dept_Department__addStaffMembers__gqlv_action",
+        "description" : null,
+        "fields" : [ {
+          "name" : "hidden",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "Boolean",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "disabled",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "String",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "validate",
+          "description" : null,
+          "args" : [ {
+            "name" : "staffMembers",
+            "description" : null,
+            "type" : {
+              "kind" : "LIST",
+              "name" : null,
+              "ofType" : {
+                "kind" : "INPUT_OBJECT",
+                "name" : "university_dept_StaffMember__gqlv_input",
+                "ofType" : null
+              }
+            },
+            "defaultValue" : null
+          } ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "String",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "invokeIdempotent",
+          "description" : null,
+          "args" : [ {
+            "name" : "staffMembers",
+            "description" : null,
+            "type" : {
+              "kind" : "LIST",
+              "name" : null,
+              "ofType" : {
+                "kind" : "INPUT_OBJECT",
+                "name" : "university_dept_StaffMember__gqlv_input",
+                "ofType" : null
+              }
+            },
+            "defaultValue" : null
+          } ],
+          "type" : {
+            "kind" : "OBJECT",
+            "name" : "university_dept_Department",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "params",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "OBJECT",
+            "name" : "university_dept_Department__addStaffMembers__gqlv_action_params",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        } ],
+        "inputFields" : null,
+        "interfaces" : [ ],
+        "enumValues" : null,
+        "possibleTypes" : null
+      }, {
+        "kind" : "OBJECT",
+        "name" : "university_dept_Department__addStaffMembers__gqlv_action_params",
+        "description" : null,
+        "fields" : [ {
+          "name" : "staffMembers",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "OBJECT",
+            "name" : "university_dept_Department__addStaffMembers__staffMembers__gqlv_action_parameter",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        } ],
+        "inputFields" : null,
+        "interfaces" : [ ],
+        "enumValues" : null,
+        "possibleTypes" : null
+      }, {
+        "kind" : "OBJECT",
+        "name" : "university_dept_Department__addStaffMembers__staffMembers__gqlv_action_parameter",
+        "description" : null,
+        "fields" : [ {
+          "name" : "hidden",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "Boolean",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "validity",
+          "description" : null,
+          "args" : [ {
+            "name" : "staffMembers",
+            "description" : null,
+            "type" : {
+              "kind" : "LIST",
+              "name" : null,
+              "ofType" : {
+                "kind" : "INPUT_OBJECT",
+                "name" : "university_dept_StaffMember__gqlv_input",
+                "ofType" : null
+              }
+            },
+            "defaultValue" : null
+          } ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "String",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "choices",
+          "description" : null,
+          "args" : [ ],
+          "type" : {
+            "kind" : "LIST",
+            "name" : null,
+            "ofType" : {
+              "kind" : "OBJECT",
+              "name" : "university_dept_StaffMember",
+              "ofType" : null
+            }
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        }, {
+          "name" : "disabled",
+          "description" : null,
+          "args" : [ {
+            "name" : "staffMembers",
+            "description" : null,
+            "type" : {
+              "kind" : "LIST",
+              "name" : null,
+              "ofType" : {
+                "kind" : "INPUT_OBJECT",
+                "name" : "university_dept_StaffMember__gqlv_input",
+                "ofType" : null
+              }
+            },
+            "defaultValue" : null
+          } ],
+          "type" : {
+            "kind" : "SCALAR",
+            "name" : "String",
+            "ofType" : null
+          },
+          "isDeprecated" : false,
+          "deprecationReason" : null
+        } ],
+        "inputFields" : null,
+        "interfaces" : [ ],
+        "enumValues" : null,
+        "possibleTypes" : null
       }, {
         "kind" : "OBJECT",
         "name" : "university_dept_Department__changeDeptHead__gqlv_action",
diff --git a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema_types_name.approved.json b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema_types_name.approved.json
index dbe0d17065..08c8bc031a 100644
--- a/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema_types_name.approved.json
+++ b/incubator/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/e2e/Schema_IntegTest.schema_types_name.approved.json
@@ -767,6 +767,12 @@
         "name" : "university_dept_Department__addStaffMember__gqlv_action_params"
       }, {
         "name" : "university_dept_Department__addStaffMember__staffMember__gqlv_action_parameter"
+      }, {
+        "name" : "university_dept_Department__addStaffMembers__gqlv_action"
+      }, {
+        "name" : "university_dept_Department__addStaffMembers__gqlv_action_params"
+      }, {
+        "name" : "university_dept_Department__addStaffMembers__staffMembers__gqlv_action_parameter"
       }, {
         "name" : "university_dept_Department__changeDeptHead__gqlv_action"
       }, {


(causeway) 01/03: CAUSEWAY-3676: wip, adding support for collection params

Posted by da...@apache.org.
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 151645243976418b675d4f75832217145b2d7cbe
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jan 26 10:31:16 2024 +0000

    CAUSEWAY-3676: wip, adding support for collection params
---
 .../viewer/graphql/model/domain/GqlvAction.java    | 24 +++++++++++++++----
 .../graphql/model/domain/GqlvDomainObject.java     |  2 +-
 .../viewer/graphql/model/types/TypeMapper.java     | 27 +++++++++++++++++++++-
 .../src/test/resources/application-test.properties |  2 +-
 .../graphql/test/src/test/resources/schema.gql     | 20 ++++++++++++++++
 5 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
index fa95ef680a..e99ac54172 100644
--- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
+++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java
@@ -25,6 +25,7 @@ import org.apache.causeway.core.metamodel.object.ManagedObject;
 import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
 import org.apache.causeway.core.metamodel.spec.feature.ObjectAction;
 import org.apache.causeway.core.metamodel.spec.feature.ObjectActionParameter;
+import org.apache.causeway.core.metamodel.spec.feature.OneToManyActionParameter;
 import org.apache.causeway.core.metamodel.spec.feature.OneToOneActionParameter;
 import org.apache.causeway.viewer.graphql.model.context.Context;
 import org.apache.causeway.viewer.graphql.model.fetcher.BookmarkedPojoFetcher;
@@ -141,8 +142,7 @@ public class GqlvAction
         val parameters = objectAction.getParameters();
         val arguments = parameters.stream()
                 .limit(upTo)
-                .map(OneToOneActionParameter.class::cast)   // TODO: remove - we previously filter to ignore any actions that have collection parameters
-                .map(oneToOneActionParameter -> gqlArgumentFor(oneToOneActionParameter, inputContext))
+                .map(objectActionParameter -> gqlArgumentFor(objectActionParameter, inputContext))
                 .collect(Collectors.toList());
         if (!arguments.isEmpty()) {
             builder.arguments(arguments);
@@ -157,14 +157,21 @@ public class GqlvAction
 
         val parameters = objectAction.getParameters();
         val arguments = parameters.get(paramNum).stream()
-                .map(OneToOneActionParameter.class::cast)   // TODO: remove - we previously filter to ignore any actions that have collection parameters
-                .map(oneToOneActionParameter -> gqlArgumentFor(oneToOneActionParameter, inputContext))
+                .map(objectActionParameter -> gqlArgumentFor(objectActionParameter, inputContext))
                 .collect(Collectors.toList());
         if (!arguments.isEmpty()) {
             builder.arguments(arguments);
         }
     }
 
+    static GraphQLArgument gqlArgumentFor(
+            final ObjectActionParameter objectActionParameter,
+            final TypeMapper.InputContext inputContext) {
+        return objectActionParameter.isPlural()
+                ? gqlArgumentFor((OneToManyActionParameter) objectActionParameter, inputContext)
+                : gqlArgumentFor((OneToOneActionParameter) objectActionParameter, inputContext);
+    }
+
     static GraphQLArgument gqlArgumentFor(
             final OneToOneActionParameter oneToOneActionParameter,
             final TypeMapper.InputContext inputContext) {
@@ -174,6 +181,15 @@ public class GqlvAction
                 .build();
     }
 
+    static GraphQLArgument gqlArgumentFor(
+            final OneToManyActionParameter oneToManyActionParameter,
+            final TypeMapper.InputContext inputContext) {
+        return GraphQLArgument.newArgument()
+                .name(oneToManyActionParameter.getId())
+                .type(TypeMapper.inputTypeFor(oneToManyActionParameter, inputContext))
+                .build();
+    }
+
     @Override
     public ObjectSpecification getObjectSpecification() {
         return holder.getObjectSpecification();
diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
index 49f0abae38..720430e08a 100644
--- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
+++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
@@ -103,7 +103,7 @@ public class GqlvDomainObject implements GqlvAction.Holder, GqlvProperty.Holder,
         objectSpecification.streamActions(ActionScope.PRODUCTION, MixedIn.INCLUDED)
                 // TODO: for now, we ignore any actions that have any collection parameters
                 //  however, this is supportable in GraphQL, https://chat.openai.com/c/7ca721d5-865a-4765-9f90-5c28046516cd
-                .filter(objectAction -> objectAction.getParameters().stream().noneMatch(ObjectActionParameter::isPlural))
+                // .filter(objectAction -> objectAction.getParameters().stream().noneMatch(ObjectActionParameter::isPlural))
                 .forEach(objectAction -> {
                     actions.put(objectAction.getId(), new GqlvAction(this, objectAction, context));
                 });
diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapper.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapper.java
index f445f93776..f1697f4f5a 100644
--- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapper.java
+++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapper.java
@@ -31,6 +31,7 @@ import javax.ws.rs.NotSupportedException;
 
 import org.apache.causeway.commons.internal.collections._Maps;
 import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.spec.feature.OneToManyActionParameter;
 import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
 import org.apache.causeway.core.metamodel.spec.feature.OneToOneFeature;
 import org.apache.causeway.viewer.graphql.model.domain.TypeNames;
@@ -149,7 +150,31 @@ public class TypeMapper {
                 return scalarTypeFor(elementType.getCorrespondingClass());
 
             case COLLECTION:
-                // TODO ...
+                throw new IllegalArgumentException(String.format("OneToOneFeature '%s' is not expected to have a beanSort of COLLECTION", oneToOneFeature.getFeatureIdentifier().toString()));
+            default:
+                // for now
+                return Scalars.GraphQLString;
+        }
+    }
+
+    public static GraphQLList inputTypeFor(final OneToManyActionParameter oneToManyActionParameter, final InputContext inputContextUnused){
+        ObjectSpecification elementType = oneToManyActionParameter.getElementType();
+        return GraphQLList.list(TypeMapper.inputTypeFor_(elementType));
+    }
+
+    private static GraphQLInputType inputTypeFor_(final ObjectSpecification elementType){
+        switch (elementType.getBeanSort()) {
+            case ABSTRACT:
+            case ENTITY:
+            case VIEW_MODEL:
+                return typeRef(TypeNames.inputTypeNameFor(elementType));
+
+            case VALUE:
+                return scalarTypeFor(elementType.getCorrespondingClass());
+
+            case COLLECTION:
+                throw new IllegalArgumentException(String.format("ObjectSpec '%s' is not expected to have a beanSort of COLLECTION", elementType.getFullIdentifier()));
+
             default:
                 // for now
                 return Scalars.GraphQLString;
diff --git a/incubator/viewers/graphql/test/src/test/resources/application-test.properties b/incubator/viewers/graphql/test/src/test/resources/application-test.properties
index 74f02709ab..1ed5bab4ab 100644
--- a/incubator/viewers/graphql/test/src/test/resources/application-test.properties
+++ b/incubator/viewers/graphql/test/src/test/resources/application-test.properties
@@ -1,3 +1,3 @@
-#logging.level.org.springframework=DEBUG
+logging.level.org.springframework=DEBUG
 logging.level.graphql=DEBUG
 
diff --git a/incubator/viewers/graphql/test/src/test/resources/schema.gql b/incubator/viewers/graphql/test/src/test/resources/schema.gql
index 9e0b06b033..2b7fa5581b 100644
--- a/incubator/viewers/graphql/test/src/test/resources/schema.gql
+++ b/incubator/viewers/graphql/test/src/test/resources/schema.gql
@@ -2228,6 +2228,7 @@ type university_admin_AdminMenu__otherAdminAction__gqlv_action {
 type university_dept_Department {
   _gql_meta: university_dept_Department__gqlv_meta
   addStaffMember: university_dept_Department__addStaffMember__gqlv_action
+  addStaffMembers: university_dept_Department__addStaffMembers__gqlv_action
   changeDeptHead: university_dept_Department__changeDeptHead__gqlv_action
   changeName: university_dept_Department__changeName__gqlv_action
   deptHead: university_dept_Department__deptHead__gqlv_property
@@ -2255,6 +2256,25 @@ type university_dept_Department__addStaffMember__staffMember__gqlv_action_parame
   validity(staffMember: university_dept_StaffMember__gqlv_input): String
 }
 
+type university_dept_Department__addStaffMembers__gqlv_action {
+  disabled: String
+  hidden: Boolean
+  invokeIdempotent(staffMembers: [university_dept_StaffMember__gqlv_input]): university_dept_Department
+  params: university_dept_Department__addStaffMembers__gqlv_action_params
+  validate(staffMembers: [university_dept_StaffMember__gqlv_input]): String
+}
+
+type university_dept_Department__addStaffMembers__gqlv_action_params {
+  staffMembers: university_dept_Department__addStaffMembers__staffMembers__gqlv_action_parameter
+}
+
+type university_dept_Department__addStaffMembers__staffMembers__gqlv_action_parameter {
+  choices: [university_dept_StaffMember]
+  disabled(staffMembers: [university_dept_StaffMember__gqlv_input]): String
+  hidden: Boolean
+  validity(staffMembers: [university_dept_StaffMember__gqlv_input]): String
+}
+
 type university_dept_Department__changeDeptHead__gqlv_action {
   disabled: String
   hidden: Boolean