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
The following commit(s) were added to refs/heads/CAUSEWAY-3676 by this push:
new 728d29908d CAUSEWAY-3676: adds configuration
728d29908d is described below
commit 728d29908d6e90daaf5d7821c2f854a208e8ea28
Author: danhaywood <[email protected]>
AuthorDate: Fri Jan 26 17:07:17 2024 +0000
CAUSEWAY-3676: adds configuration
---
bom/pom.xml | 2 +-
.../core/config/CausewayConfiguration.java | 49 +++++-
incubator/pom.xml | 2 +-
incubator/viewers/graphql/applib/pom.xml | 4 +-
incubator/viewers/graphql/model/pom.xml | 12 +-
.../graphql/model/src/main/java/module-info.java | 1 +
.../viewer/graphql/model/types/TypeMapper.java | 185 ++-------------------
.../model/types/TypeMapperConfiguration.java | 17 ++
.../{TypeMapper.java => TypeMapperDefault.java} | 65 +++++---
incubator/viewers/graphql/pom.xml | 10 +-
incubator/viewers/graphql/test/pom.xml | 6 +-
.../src/test/resources/application-test.properties | 4 +-
incubator/viewers/graphql/viewer/pom.xml | 6 +-
...xecutionStrategyResolvingWithinInteraction.java | 47 +++++-
14 files changed, 186 insertions(+), 224 deletions(-)
diff --git a/bom/pom.xml b/bom/pom.xml
index 510c6111d8..bca89b9650 100644
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -1433,7 +1433,7 @@ It is therefore a copy of org.apache:apache, with
customisations clearly identif
<!-- org.apache.causeway.incubator.viewer -->
<dependency>
<groupId>org.apache.causeway.incubator.viewer</groupId>
- <artifactId>causeway-viewer-graphql</artifactId>
+
<artifactId>causeway-viewer-graphql-viewer</artifactId>
<version>2.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>compile</scope>
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 79e67cba29..5700aa3563 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
@@ -231,7 +231,7 @@ public class CausewayConfiguration {
* Setting this option to {@literal true} allows {@code
CsrfFilter}(s) to be
* configured. Yet EXPERIMENTAL.
*
- * @see org.springframework.security.web.csrf.CsrfFilter
+ * @see
<code>org.springframework.security.web.csrf.CsrfFilter</code>
* @see
"https://www.baeldung.com/spring-security-registered-filters"
*/
private boolean allowCsrfFilters = false;
@@ -2342,6 +2342,53 @@ public class CausewayConfiguration {
}
}
+ private final Gqlv gqlv = new Gqlv();
+ @Data
+ public static class Gqlv {
+
+ private final MetaData metaData = new MetaData();
+ @Data
+ public static class MetaData {
+ private String idAttributeName = "__id";
+ private String logicalTypeNameAttributeName = "__type";
+ private String versionAttributeName = "__version";
+ }
+
+ private final TypeMapper typeMapper = new TypeMapper();
+ @Data
+ public static class TypeMapper {
+
+ /**
+ * For both JDK8's {@link java.time.LocalDate} and JodaTime's
{@link org.joda.time.LocalDate}
+ */
+ private String localDateFormat = "yyyy-MM-dd";
+ /**
+ * for JDK8's {@link java.time.ZonedDateTime} and JodaTime's
{@link org.joda.time.DateTime}
+ */
+ private String zonedDateTimeFormat = "yyyy-MM-dd HH:mm:ss z";
+
+ }
+
+ @Getter
+ private final Authentication authentication = new Authentication();
+ @Data
+ public static class Authentication {
+
+ @Getter
+ private final Fallback fallback = new Fallback();
+ @Data
+ public static class Fallback {
+
+ /**
+ * Used as the default username if not provided by other
means.
+ */
+ private String username;
+ private List<String> roles;
+ }
+ }
+
+ }
+
private final Restfulobjects restfulobjects = new Restfulobjects();
@Data
public static class Restfulobjects {
diff --git a/incubator/pom.xml b/incubator/pom.xml
index b042d2cc87..0edd7e2eb6 100644
--- a/incubator/pom.xml
+++ b/incubator/pom.xml
@@ -217,7 +217,7 @@
<dependency>
<groupId>org.apache.causeway.incubator.viewer</groupId>
- <artifactId>causeway-viewer-graphql</artifactId>
+
<artifactId>causeway-viewer-graphql-viewer</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
diff --git a/incubator/viewers/graphql/applib/pom.xml
b/incubator/viewers/graphql/applib/pom.xml
index bcb20f73e5..5fa363dffd 100644
--- a/incubator/viewers/graphql/applib/pom.xml
+++ b/incubator/viewers/graphql/applib/pom.xml
@@ -24,13 +24,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>causeway-viewer-graphql-applib</artifactId>
- <name>Apache Causeway Inc - Viewer GraphQL (Applib)</name>
+ <name>Apache Causeway Viewer - GraphQL (Applib)</name>
<properties>
<jar-plugin.automaticModuleName>org.apache.causeway.incubator.viewer.graphql.applib</jar-plugin.automaticModuleName>
diff --git a/incubator/viewers/graphql/model/pom.xml
b/incubator/viewers/graphql/model/pom.xml
index 8339463606..f03dc54daf 100644
--- a/incubator/viewers/graphql/model/pom.xml
+++ b/incubator/viewers/graphql/model/pom.xml
@@ -24,13 +24,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>causeway-viewer-graphql-model</artifactId>
- <name>Apache Causeway Inc - Viewer GraphQL (Model)</name>
+ <name>Apache Causeway Viewer - GraphQL (Model)</name>
<properties>
<jar-plugin.automaticModuleName>org.apache.causeway.incubator.viewer.graphql.model</jar-plugin.automaticModuleName>
@@ -45,7 +45,7 @@
</dependency>
<dependency>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-applib</artifactId>
</dependency>
@@ -59,6 +59,12 @@
</exclusion>
</exclusions>
</dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-autoconfigure</artifactId>
+ </dependency>
+
<dependency>
<!-- override spring, for security and bug-fixes -->
<groupId>com.graphql-java</groupId>
diff --git a/incubator/viewers/graphql/model/src/main/java/module-info.java
b/incubator/viewers/graphql/model/src/main/java/module-info.java
index 8654827e5f..0941b42afc 100644
--- a/incubator/viewers/graphql/model/src/main/java/module-info.java
+++ b/incubator/viewers/graphql/model/src/main/java/module-info.java
@@ -13,4 +13,5 @@ module org.apache.causeway.incubator.viewer.graphql.model {
requires spring.context;
requires org.apache.causeway.core.metamodel;
requires com.graphqljava;
+ requires spring.boot.autoconfigure;
}
\ No newline at end of file
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 7612b6d005..5f40e8a010 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
@@ -47,189 +47,32 @@ import org.springframework.stereotype.Component;
import static graphql.schema.GraphQLNonNull.nonNull;
import static graphql.schema.GraphQLTypeReference.typeRef;
-@Component
-@Priority(PriorityPrecedence.LATE)
-public class TypeMapper {
-
- private static <K,V> Map.Entry<K,V> pair(K key, V value) {
- return new Map.Entry<K, V>() {
- @Override public K getKey() {return key;}
- @Override public V getValue() {return value;}
- @Override public V setValue(V value) { throw new
NotSupportedException("Immutable"); }
- };
- }
-
- private static final Map<Class<?>, GraphQLScalarType> SCALAR_BY_CLASS =
_Maps.unmodifiableEntries(
-
- pair(int.class, Scalars.GraphQLInt),
- pair(Integer.class, Scalars.GraphQLInt),
- pair(Short.class, Scalars.GraphQLInt),
- pair(short.class, Scalars.GraphQLInt),
- pair(BigInteger.class, Scalars.GraphQLInt),
-
- pair(float.class, Scalars.GraphQLFloat),
- pair(Float.class, Scalars.GraphQLFloat),
- pair(double.class, Scalars.GraphQLFloat),
- pair(Double.class, Scalars.GraphQLFloat),
- pair(long.class, Scalars.GraphQLFloat),
- pair(Long.class, Scalars.GraphQLFloat),
- pair(BigDecimal.class, Scalars.GraphQLFloat),
-
- pair(boolean.class, Scalars.GraphQLBoolean),
- pair(Boolean.class, Scalars.GraphQLBoolean)
- );
-
- public GraphQLScalarType scalarTypeFor(final Class<?> c){
- return SCALAR_BY_CLASS.getOrDefault(c, Scalars.GraphQLString);
- }
+public interface TypeMapper {
- public GraphQLOutputType outputTypeFor(final OneToOneFeature
oneToOneFeature) {
- ObjectSpecification otoaObjectSpec = oneToOneFeature.getElementType();
- switch (otoaObjectSpec.getBeanSort()) {
+ GraphQLScalarType scalarTypeFor(final Class<?> c);
- case VIEW_MODEL:
- case ENTITY:
-
- GraphQLTypeReference fieldTypeRef =
typeRef(TypeNames.objectTypeNameFor(otoaObjectSpec));
- return oneToOneFeature.isOptional()
- ? fieldTypeRef
- : nonNull(fieldTypeRef);
-
- case VALUE:
-
- GraphQLScalarType scalarType =
scalarTypeFor(otoaObjectSpec.getCorrespondingClass());
-
- return oneToOneFeature.isOptional()
- ? scalarType
- : nonNull(scalarType);
- }
- return null;
- }
+ GraphQLOutputType outputTypeFor(final OneToOneFeature oneToOneFeature);
@Nullable
- public GraphQLOutputType outputTypeFor(final ObjectSpecification
objectSpecification){
+ GraphQLOutputType outputTypeFor(final ObjectSpecification
objectSpecification);
- switch (objectSpecification.getBeanSort()){
- case ABSTRACT:
- case ENTITY:
- case VIEW_MODEL:
- return
typeRef(TypeNames.objectTypeNameFor(objectSpecification));
-
- case VALUE:
- return
scalarTypeFor(objectSpecification.getCorrespondingClass());
-
- case COLLECTION:
- // should be noop
- return null;
-
- default:
- // for now
- return Scalars.GraphQLString;
- }
- }
-
- @Nullable public GraphQLList listTypeForElementTypeOf(OneToManyAssociation
oneToManyAssociation) {
- ObjectSpecification elementType =
oneToManyAssociation.getElementType();
- return listTypeFor(elementType);
- }
+ @Nullable
+ GraphQLList listTypeForElementTypeOf(OneToManyAssociation
oneToManyAssociation);
- @Nullable public GraphQLList listTypeFor(ObjectSpecification elementType) {
- switch (elementType.getBeanSort()) {
- case VIEW_MODEL:
- case ENTITY:
- return
GraphQLList.list(typeRef(TypeNames.objectTypeNameFor(elementType)));
- case VALUE:
- return
GraphQLList.list(scalarTypeFor(elementType.getCorrespondingClass()));
- }
- return null;
- }
+ @Nullable
+ GraphQLList listTypeFor(ObjectSpecification elementType);
- public GraphQLInputType inputTypeFor(
+ GraphQLInputType inputTypeFor(
final OneToOneFeature oneToOneFeature,
- final InputContext inputContext) {
- return oneToOneFeature.isOptional() ||
inputContext.isOptionalAlwaysAllowed()
- ? inputTypeFor_(oneToOneFeature)
- : nonNull(inputTypeFor_(oneToOneFeature));
- }
+ final InputContext inputContext);
- private GraphQLInputType inputTypeFor_(final OneToOneFeature
oneToOneFeature){
- ObjectSpecification elementType = oneToOneFeature.getElementType();
- 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("OneToOneFeature '%s' is not expected to
have a beanSort of COLLECTION",
oneToOneFeature.getFeatureIdentifier().toString()));
- default:
- // for now
- return Scalars.GraphQLString;
- }
- }
-
- public GraphQLList inputTypeFor(final OneToManyActionParameter
oneToManyActionParameter, final InputContext inputContextUnused){
- ObjectSpecification elementType =
oneToManyActionParameter.getElementType();
- return GraphQLList.list(inputTypeFor_(elementType));
- }
-
- private 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());
+ GraphQLList inputTypeFor(final OneToManyActionParameter
oneToManyActionParameter, final InputContext inputContextUnused);
- 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;
- }
- }
-
- public Object adaptPojo(
+ Object adaptPojo(
final Object argumentValue,
- final ObjectSpecification elementType) {
- val elementClazz = elementType.getCorrespondingClass();
-
- if (elementClazz.isEnum()) {
- return Enum.valueOf((Class<Enum>) elementClazz,
argumentValue.toString());
- }
-
- if (elementClazz == BigInteger.class) {
- return BigInteger.valueOf((Integer) argumentValue);
- }
-
- if (elementClazz == BigDecimal.class) {
- return BigDecimal.valueOf((Double) argumentValue);
- }
-
- if (elementClazz == LocalDate.class) {
- String argumentStr = (String) argumentValue;
- return LocalDate.parse(argumentStr,
DateTimeFormatter.ofPattern("yyyy-MM-dd"));
- }
-
- if (elementClazz == org.joda.time.LocalDate.class) {
- String argumentStr = (String) argumentValue;
- return org.joda.time.LocalDate.parse(argumentStr,
org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd"));
- }
-
- if (elementClazz == float.class || elementClazz == Float.class) {
- return ((Double) argumentValue).floatValue();
- }
-
- return argumentValue;
- }
+ final ObjectSpecification elementType);
- public enum InputContext {
+ enum InputContext {
HIDE,
DISABLE,
VALIDATE,
diff --git
a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapperConfiguration.java
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapperConfiguration.java
new file mode 100644
index 0000000000..5eb9ea11d3
--- /dev/null
+++
b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapperConfiguration.java
@@ -0,0 +1,17 @@
+package org.apache.causeway.viewer.graphql.model.types;
+
+import org.apache.causeway.core.config.CausewayConfiguration;
+
+import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class TypeMapperConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(TypeMapper.class)
+ public TypeMapper defaultTypeMapper(final CausewayConfiguration
causewayConfiguration) {
+ return new TypeMapperDefault(causewayConfiguration);
+ }
+}
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/TypeMapperDefault.java
similarity index 85%
copy from
incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapper.java
copy to
incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/types/TypeMapperDefault.java
index 7612b6d005..f521f2ff88 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/TypeMapperDefault.java
@@ -21,18 +21,23 @@ package org.apache.causeway.viewer.graphql.model.types;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
+import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
-import graphql.Scalars;
-import graphql.schema.*;
-
-import lombok.experimental.UtilityClass;
-import lombok.val;
-
import javax.annotation.Priority;
+import javax.inject.Inject;
import javax.ws.rs.NotSupportedException;
+import org.apache.causeway.core.config.CausewayConfiguration;
+
+import org.joda.time.DateTime;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.lang.Nullable;
+import org.springframework.stereotype.Component;
+
import org.apache.causeway.applib.annotation.PriorityPrecedence;
import org.apache.causeway.commons.internal.collections._Maps;
import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
@@ -41,15 +46,24 @@ 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;
-import org.springframework.lang.Nullable;
-import org.springframework.stereotype.Component;
+import lombok.RequiredArgsConstructor;
+import lombok.val;
+
+import graphql.Scalars;
+import graphql.schema.GraphQLInputType;
+import graphql.schema.GraphQLList;
+import graphql.schema.GraphQLOutputType;
+import graphql.schema.GraphQLScalarType;
+import graphql.schema.GraphQLTypeReference;
import static graphql.schema.GraphQLNonNull.nonNull;
import static graphql.schema.GraphQLTypeReference.typeRef;
-@Component
-@Priority(PriorityPrecedence.LATE)
-public class TypeMapper {
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
+public class TypeMapperDefault implements TypeMapper {
+
+ @SuppressWarnings("CdiInjectInspection")
+ @Inject private final CausewayConfiguration causewayConfiguration;
private static <K,V> Map.Entry<K,V> pair(K key, V value) {
return new Map.Entry<K, V>() {
@@ -212,14 +226,25 @@ public class TypeMapper {
return BigDecimal.valueOf((Double) argumentValue);
}
+ val typeMapperConfig =
causewayConfiguration.getViewer().getGqlv().getTypeMapper();
if (elementClazz == LocalDate.class) {
String argumentStr = (String) argumentValue;
- return LocalDate.parse(argumentStr,
DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+ return LocalDate.parse(argumentStr,
DateTimeFormatter.ofPattern(typeMapperConfig.getLocalDateFormat()));
}
if (elementClazz == org.joda.time.LocalDate.class) {
String argumentStr = (String) argumentValue;
- return org.joda.time.LocalDate.parse(argumentStr,
org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd"));
+ return org.joda.time.LocalDate.parse(argumentStr,
org.joda.time.format.DateTimeFormat.forPattern(typeMapperConfig.getLocalDateFormat()));
+ }
+
+ if (elementClazz == ZonedDateTime.class) {
+ String argumentStr = (String) argumentValue;
+ return ZonedDateTime.parse(argumentStr,
DateTimeFormatter.ofPattern(typeMapperConfig.getZonedDateTimeFormat()));
+ }
+
+ if (elementClazz == DateTime.class) {
+ String argumentStr = (String) argumentValue;
+ return DateTime.parse(argumentStr,
org.joda.time.format.DateTimeFormat.forPattern(typeMapperConfig.getLocalDateFormat()));
}
if (elementClazz == float.class || elementClazz == Float.class) {
@@ -229,18 +254,4 @@ public class TypeMapper {
return argumentValue;
}
- public enum InputContext {
- HIDE,
- DISABLE,
- VALIDATE,
- CHOICES,
- AUTOCOMPLETE,
- DEFAULT,
- INVOKE,
- SET,
- ;
- boolean isOptionalAlwaysAllowed() {
- return !(this == INVOKE || this == SET);
- }
- }
}
diff --git a/incubator/viewers/graphql/pom.xml
b/incubator/viewers/graphql/pom.xml
index 8a4cf8a6ec..7cdca9e2d2 100644
--- a/incubator/viewers/graphql/pom.xml
+++ b/incubator/viewers/graphql/pom.xml
@@ -45,9 +45,9 @@
<relativePath>../../../core/pom.xml</relativePath>
</parent>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql</artifactId>
- <name>Apache Causeway Inc - Viewer GraphQL</name>
+ <name>Apache Causeway Viewer - GraphQL</name>
<packaging>pom</packaging>
@@ -59,19 +59,19 @@
<dependencies>
<dependency>
-
<groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-applib</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
-
<groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-model</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
-
<groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-viewer</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
diff --git a/incubator/viewers/graphql/test/pom.xml
b/incubator/viewers/graphql/test/pom.xml
index 10862d6375..5aa6099832 100644
--- a/incubator/viewers/graphql/test/pom.xml
+++ b/incubator/viewers/graphql/test/pom.xml
@@ -24,13 +24,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>causeway-viewer-graphql-test</artifactId>
- <name>Apache Causeway Inc - Viewer GraphQL (Test)</name>
+ <name>Apache Causeway Viewer - GraphQL (Test)</name>
<properties>
<jar-plugin.automaticModuleName>org.apache.causeway.incubator.viewer.graphql.test</jar-plugin.automaticModuleName>
@@ -67,7 +67,7 @@
<dependencies>
<dependency>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-viewer</artifactId>
</dependency>
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 1ed5bab4ab..54fc4d657b 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.graphql=DEBUG
+#logging.level.org.springframework=DEBUG
+#logging.level.graphql=DEBUG
diff --git a/incubator/viewers/graphql/viewer/pom.xml
b/incubator/viewers/graphql/viewer/pom.xml
index c63762fee6..d9ddfb6ad8 100644
--- a/incubator/viewers/graphql/viewer/pom.xml
+++ b/incubator/viewers/graphql/viewer/pom.xml
@@ -24,13 +24,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>causeway-viewer-graphql-viewer</artifactId>
- <name>Apache Causeway Inc - Viewer GraphQL (Viewer)</name>
+ <name>Apache Causeway Viewer - GraphQL (Viewer)</name>
<properties>
<jar-plugin.automaticModuleName>org.apache.causeway.incubator.viewer.graphql.viewer</jar-plugin.automaticModuleName>
@@ -48,7 +48,7 @@
<dependencies>
<dependency>
- <groupId>org.apache.causeway.incubator.viewer</groupId>
+ <groupId>org.apache.causeway.viewer</groupId>
<artifactId>causeway-viewer-graphql-model</artifactId>
</dependency>
diff --git
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/AsyncExecutionStrategyResolvingWithinInteraction.java
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/AsyncExecutionStrategyResolvingWithinInteraction.java
index a94655eb96..816086b4d6 100644
---
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/AsyncExecutionStrategyResolvingWithinInteraction.java
+++
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/AsyncExecutionStrategyResolvingWithinInteraction.java
@@ -18,10 +18,17 @@
*/
package org.apache.causeway.viewer.graphql.viewer.integration;
+import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject;
+import org.apache.causeway.applib.services.iactnlayer.InteractionContext;
+import org.apache.causeway.applib.services.user.RoleMemento;
+import org.apache.causeway.applib.services.user.UserMemento;
+import org.apache.causeway.commons.collections.Can;
+import org.apache.causeway.core.config.CausewayConfiguration;
+
import org.springframework.stereotype.Service;
import org.apache.causeway.applib.services.iactnlayer.InteractionService;
@@ -33,21 +40,51 @@ import graphql.execution.FieldValueInfo;
import lombok.RequiredArgsConstructor;
@Service
-@RequiredArgsConstructor(onConstructor_ = {@Inject})
public class AsyncExecutionStrategyResolvingWithinInteraction extends
AsyncExecutionStrategy {
private final InteractionService interactionService;
+ private final UserMemento userMemento;
+
+ public AsyncExecutionStrategyResolvingWithinInteraction(
+ final InteractionService interactionService,
+ final CausewayConfiguration causewayConfiguration) {
+ this.interactionService = interactionService;
+
+ String fallbackUsername =
causewayConfiguration.getViewer().getGqlv().getAuthentication().getFallback().getUsername();
+ List<String> fallbackRoles =
causewayConfiguration.getViewer().getGqlv().getAuthentication().getFallback().getRoles();
+ userMemento = fallbackUsername != null
+ ? UserMemento.builder()
+ .name(fallbackUsername)
+ .roles(Can.ofStream(
+ fallbackRoles.stream()
+ .map(roleName ->
RoleMemento.builder()
+
.name(roleName)
+ .build()
+ )
+ )
+ ).build()
+ : null;
+ }
+
+
@Override
protected CompletableFuture<FieldValueInfo> resolveFieldWithInfo(
final ExecutionContext executionContext,
final ExecutionStrategyParameters parameters) {
// TODO: propagate identity from executionContext
-//
interactionService.openInteraction(InteractionContext.builder().user(UserMemento.builder().build()).build());
+ //
interactionService.openInteraction(InteractionContext.builder().user(UserMemento.builder().build()).build());
- return interactionService.callAnonymous( () -> {
- return super.resolveFieldWithInfo(executionContext, parameters);
- });
+ if (userMemento != null) {
+ return interactionService.call(
+ InteractionContext.builder().user(userMemento).build(),
+ () -> super.resolveFieldWithInfo(executionContext,
parameters)
+ );
+ } else {
+ return interactionService.callAnonymous(
+ () -> super.resolveFieldWithInfo(executionContext,
parameters)
+ );
+ }
}
}