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/02/25 18:35:17 UTC

(causeway) branch master updated: CAUSEWAY-3676: updates docs is all

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

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


The following commit(s) were added to refs/heads/master by this push:
     new e8844651f3 CAUSEWAY-3676: updates docs is all
e8844651f3 is described below

commit e8844651f35402e622235102f624fd48b2e10112
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Feb 25 18:34:17 2024 +0000

    CAUSEWAY-3676: updates docs is all
---
 .../core/config/CausewayConfiguration.java         |   2 +-
 viewers/graphql/adoc/modules/ROOT/pages/about.adoc | 394 ++++++++++++++++++---
 2 files changed, 337 insertions(+), 59 deletions(-)

diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index 14c91f7a5e..cd2e9f3609 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -2438,7 +2438,7 @@ public class CausewayConfiguration {
 
             public enum ApiVariant {
                 /**
-                 * Exposes only a Query API, of properties, collections and safe (query-onl) actions.
+                 * Exposes only a Query API, of properties, collections and safe (query-only) actions.
                  * Any actions that mutate the state of the system (in other words are idempotent or non-idempotent)
                  * are excluded from the API, as is the ability to set properties.
                  */
diff --git a/viewers/graphql/adoc/modules/ROOT/pages/about.adoc b/viewers/graphql/adoc/modules/ROOT/pages/about.adoc
index dc35227752..9368b5a2ae 100644
--- a/viewers/graphql/adoc/modules/ROOT/pages/about.adoc
+++ b/viewers/graphql/adoc/modules/ROOT/pages/about.adoc
@@ -2,10 +2,78 @@
 
 :Notice: 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 ag [...]
 
-The GraphQL viewer automatically exposes an Apache Causeway domain object model as a link:https://graphql.org/[graphql] API.
-It is implemented using link:https://spring.io/projects/spring-graphql[Spring GraphQL] project, which in turn is built on top of link:https://www.graphql-java.com/[GraphQL Java].
+The GraphQL viewer automatically exposes an Apache Causeway domain object model as a link:https://graphql.org/[GraphQL] API.
+The viewer iterates over the domain services and domain objects, with their actions, properties and collections represented as fields within the graph.
+Actions that take parameters are mapped to fields with arguments.
+
+The GraphQL viewer is implemented using link:https://spring.io/projects/spring-graphql[Spring GraphQL] project, which in turn is built on top of link:https://www.graphql-java.com/[GraphQL Java].
 This also means that it automatically provides the link:https://github.com/graphql/graphiql[GraphiQL] interactive query tool.
 
+== Concepts
+
+=== API Variants
+
+The GraphQL viewer supports 3 different API variants, controlled by the xref:refguide:config:sections/causeway.viewer.graphql.adoc#causeway.viewer.graphql.api-variant[causeway.viewer.graphql.api-variant] configuration property:
+
+* `QUERY_ONLY`
++
+Exposes only a Query API, of properties, collections and safe (query-onl) actions.
+Any actions that mutate the state of the system (in other words are idempotent or non-idempotent are excluded from the API, as is the ability to set properties.
+
+* `QUERY_AND_MUTATIONS`
++
+Exposes an API with Query for query/safe separate queries and field access, with mutating (idempotent and non-idempotent) actions and property setters instead surfaced as Mutations, as per the link:https://spec.graphql.org/June2018/#sec-Language.Operations[GraphQL spec].
+
+* `QUERY_WITH_MUTATIONS_NON_SPEC_COMPLIANT`
++
+Exposes an API with both Query and Mutations, but relaxes the constraints for the Query API by also including idempotent and non-idempotent actions and property setters.
++
+Note that the actions _are_ also available through as Mutations (same as with `QUERY_AND_MUTATIONS` API variant).
++
+[IMPORTANT]
+Be aware that the resultant API is not compliant with the rules of the
+GraphQL spec; in particular, it violates link:https://spec.graphql.org/June2018/#sec-Language.Operations[2.3 Operations] which states: "query – [is] a read‐only fetch";
+
+So the API variant primarily relates to how mutating (non-safe) actions are handled.
+
+
+
+=== Rich vs Simple Schemas
+
+The viewer can represent the domain model as either a "rich" GraphQL schema, or a "simple" GraphQL schema; or indeed both can be supported ath the same time.
+
+The *rich schema* represents all the behaviour and structure of the Causeway domain model:
+
+* hidden, disabled, validate
+* choices, autoComplete, defaults
+* obtain ("get") the value
+
+In other words, it exposes not only the core data/behaviour but also of the supporting methods.
+
+The *simple schema* represents just the core data/behaviour, but does not include the supporting method facets.
+
+With the rich schema, the application logic and business domain logic remains the concern of the server, with the calling client app responsible only for presentation logic.
+In fact, the rich schemas is so rich that one could in theory implement a fully generic UI client.
+
+With the simple schema, although the main business domain logic remains the concern of the server, the application logic moves to the client.
+For example, if there is a drop-down list box, the client needs to know how to obtain the list of choices.
+But the benefit of the simple schema is, well, that it is simpler; in other words more "intuitive" and less "verbose".
+
+The xref:refguide:config:sections/causeway.viewer.graphql.adoc#causeway.viewer.graphql.schema-style[causeway.viewer.graphql.schema-style] configuration property specifies which schema (or both) is supported:
+
+* `SIMPLE_ONLY` - exposes only the "simple" schema
+* `RICH_ONLY` - exposes only the "rich" schema
+* `SIMPLE_AND_RICH` - exposes both the simple and rich schemas, the top-level query for each residing under either the `simple` or `rich` field respectively.
++
+For the top-level mutation, the "simple" schema is used.
+
+* `RICH_AND_SIMPLE` - also exposes both the simple and rich schemas, the top-level query for each residing under either the `simple` or `rich` field respectively.
++
+For the top-level mutation, the "rich" schema is used.
+
+
+
+
 == Example
 
 How the viewer works is probably most easily explained by an example.
@@ -17,27 +85,40 @@ GraphQL distinguishes queries and mutations, so let's look at each.
 
 NOTE: GraphQL also defines the notion of subscriptions; the GraphQL viewer currently has no support for these.
 
+We'll assume here that the `SIMPLE_AND_RICH` schema style is in use:
+
 === Queries
 
-To list all Departments, we can submit this query:
+To list all Departments, we can submit this query using either the "rich" schema or "simple" schema:
+
+[cols="1a,1a", options="header"]
+|===
 
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 {
-  university_dept_Departments {
-    findAllDepartments {
-      invoke {                  #<.>
-        name {
-          get                   #<.>
-        }
-        staffMembers {
-          get {                 #<.>
+  rich {                          #<.>
+    university_dept_Departments { #<.>
+      findAllDepartments {        #<.>
+        invoke {                  #<.>
+          results {               #<.>
             name {
-              get               #<.>
+              get                 #<.>
             }
-            _gqlv_meta {
-              id                #<.>
-              logicalTypeName   #<5>
+            staffMembers {
+              get {               #<.>
+                name {
+                  get             #<.>
+                }
+                _meta {
+                  id              #<.>
+                  logicalTypeName #<9>
+                }
+              }
             }
           }
         }
@@ -46,34 +127,78 @@ To list all Departments, we can submit this query:
   }
 }
 ----
-<.> invokes the action, returning a list of ``Department``s
+
+|
+[source,graphql]
+----
+{
+  simple {                        #<1>
+    university_dept_Departments { #<2>
+      findAllDepartments {        #<3><4><5>
+        name                      #<6>
+        staffMembers {            #<7>
+          name                    #<8>
+          _meta {
+            id                    #<9>
+            logicalTypeName       #<9>
+          }
+        }
+      }
+    }
+  }
+}
+----
+|===
+<.> specify schema style
+<.> domain service
+<.> action name
+<.> invokes the action
+<.> returning a list of ``Department``s
 <.> gets (accesses) the `name` property of each returned `Department`
 <.> also gets (accesses) the `staffMembers` collection of each returned `Department`, returning a list of ``StaffMember``s
 <.> gets the `name` prperty for each returned `StaffMember`
 <.> returns the internal id and logicalTypeName of each `StaffMember`.
 Together, these make up the xref:refguide:applib:index/services/bookmark/Bookmark.adoc[] of the domain object.
 
-As well as accessing properties and collections and invoking (safe) actions, the GraphQL viewer also allows access to the usual supporting semantics.
+
+
+But if using the "rich" schema, then as well as accessing properties and collections and invoking (safe) actions, the GraphQL viewer also allows access to the usual supporting semantics.
 For example:
 
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 {
-  university_dept_Departments {
-    findAllDepartments {
-      disabled          #<.>
-      invoke {
-        name {
-          hidden        #<.>
+  rich {
+    university_dept_Departments {
+      findAllDepartments {
+        disabled          #<.>
+        invoke {
+          results {
+            name {
+              hidden        #<.>
+            }
+          }
         }
       }
     }
   }
 }
 ----
+|
+Not supported by simple schema.
+|===
+
 <.> whether this action is disabled
 <.> whether the property of the resultant object is hidden
 
+
 Similarly, there are fields for action parameters:
 
 * `validate` - is the proposed action parameter valid?
@@ -90,6 +215,7 @@ There are also similar fields for properties:
 * `autoComplete` - for a property , is there an auto-complete?
 
 
+
 The next section explains how use mutations to change the state of the system.
 
 === Mutations
@@ -101,6 +227,13 @@ IF the action is on a domain service, then the target is implicit; but if the ac
 
 For example, to invoke a mutating action on a domain service:
 
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 mutation {
@@ -114,15 +247,38 @@ mutation {
   }
 }
 ----
+
+|
+[source,graphql]
+----
+mutation {
+  university_dept_Departments__createDepartment(
+      name: "Geophysics",
+      deptHead: null
+  ) {
+    name
+  }
+}
+----
+
+|===
 <.> derived from the logical type name of the domain service, and the action Id.
 
-For example, to invoke a mutating action on a domain object:
 
+For example, to invoke a mutating action on a domain object
+
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 mutation {
   university_dept_Department__changeName(     # <.>
-      _gqlv_target: {id : "1"},               # <.>
+      _target: {id : "1"},                     # <.>
       newName: "Classics and Ancient History"
   ) {
     name {
@@ -131,31 +287,65 @@ mutation {
   }
 }
 ----
+
+|
+[source,graphql]
+----
+mutation {
+  university_dept_Department__changeName(
+      _target: {id : "1"},
+      newName: "Classics and Ancient History"
+  ) {
+    name
+  }
+}
+----
+
+|===
 <.> derived from the logical type name of the domain object, and the action Id.
-<.> the `_gqlv_target` specifies the target object
+<.> the `object` argument specifies the target object
 
 
 Or, to set a property on a domain object:
 
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 mutation {
-  university_dept_StaffMember__name(    #<.>
-      _gqlv_target: {id: "1"},          #<.>
+  university_dept_StaffMember__name(  #<.>
+      _target: {id: "1"},             #<.>
       name: "Jonathon Gartner"
   ) {
-    name {                              #<.>
+    name {                            #<.>
       get
     }
   }
 }
 ----
-<.> derived from the logical type name of the domain object, and the property Id.
-<.> the `_gqlv_target` specifies the target object
-<.> property setters are `void`, so as a convenience the mutator instead returns the target object.
-
 
+|
+[source,graphql]
+----
+mutation {
+  university_dept_StaffMember__name(
+      _target: {id: "1"},
+      name: "Jonathon Gartner"
+  ) {
+    name
+  }
+}
+----
 
+|===
+<.> derived from the logical type name of the domain object, and the property Id.
+<.> the `_target` argument specifies the target object
+<.> property setters are `void`, so as a convenience the mutator instead returns the target object.
 
 === Mutations using Queries
 
@@ -171,46 +361,90 @@ As specified by xref:refguide:applib:index/annotation/Action.adoc#semantics[@Act
 * `set` - to modify a property.
 
 
-For example, to invoke an action on a domain service
+For example, to invoke an action on a domain service:
+
+[cols="1a,1a", options="header"]
+|===
 
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 {
-  university_dept_Staff {
-    createStaffMember {
-      invokeNonIdempotent(
-        name: "Dr. Georgina McGovern",
-        department: { id: "1"}
-    ) {
-        name {
-          get
-        }
-        department {
-          get {
+  rich {
+    university_dept_Staff {
+      createStaffMember {
+        invokeNonIdempotent(
+          name: "Dr. Georgina McGovern",
+          department: { id: "1"}
+      ) {
+          results {
             name {
               get
             }
+            department {
+              get {
+                name {
+                  get
+                }
+              }
+            }
           }
         }
       }
     }
   }
 }
+----
 
+|
+[source,graphql]
 ----
+{
+  simple {
+    university_dept_Staff {
+      createStaffMember (
+          name: "Dr. Georgina McGovern",
+          department: { id: "1"}
+      ) {
+        name
+        department {
+          name
+        }
+      }
+    }
+  }
+}
+----
+|===
 
 Or, to find a domain object and then invoke a mutating action on it:
 
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 {
-  university_dept_DeptHeads {
-    findHeadByName {
-      invoke(name: "Prof. Dicky Horwich") {
-        changeName {
-          invokeIdempotent(newName: "Prof. Richard Horwich") {
-            name {
-              get
+  rich {
+    university_dept_DeptHeads {
+      findHeadByName {
+        invoke(name: "Prof. Dicky Horwich") {
+          results {
+            changeName {
+              invokeIdempotent(newName: "Prof. Richard Horwich") {
+                results {
+                  name {
+                    get
+                  }
+                }
+              }
             }
           }
         }
@@ -219,19 +453,46 @@ Or, to find a domain object and then invoke a mutating action on it:
   }
 }
 ----
+|
+[source,graphql]
+----
+{
+  simple {
+    university_dept_DeptHeads {
+      findHeadByName(name: "Prof. Dicky Horwich") {
+        changeName(newName: "Prof. Richard Horwich") {
+          name
+        }
+      }
+    }
+  }
+}
+----
+|===
 
 Or, similarly to find a domain object and then set a property afterwards:
 
+[cols="1a,1a", options="header"]
+|===
+
+|Rich schema
+|Simple schema
+
+|
 [source,graphql]
 ----
 {
-  university_dept_Staff {
-    findStaffMemberByName {
-      invoke(name: "Gerry Jones") {
-        name {
-          set(name: "Gerald Johns") {
+  rich {
+    university_dept_Staff {
+      findStaffMemberByName {
+        invoke(name: "Gerry Jones") {
+          results {
             name {
-              get
+              set(name: "Gerald Johns") {
+                name {
+                  get
+                }
+              }
             }
           }
         }
@@ -241,6 +502,23 @@ Or, similarly to find a domain object and then set a property afterwards:
 }
 ----
 
+|
+[source,graphql]
+----
+{
+  simple {
+    university_dept_Staff {
+      findStaffMemberByName(name: "Gerry Jones") {
+        name(name: "Gerald Johns") {
+          name
+        }
+      }
+    }
+  }
+}
+----
+|===
+
 
 This relaxed mode is specified using a configuration property, see xref:setup-and-configuration.adoc[].