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/19 23:48:58 UTC
(causeway) 02/03: CAUSEWAY-3676: simplifies GDO a little
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 41e1164c8d276189fdad5256e71d8bafa826961d
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Mon Feb 19 20:08:40 2024 +0000
CAUSEWAY-3676: simplifies GDO a little
---
.../graphql/model/domain/GqlvAbstractCustom.java | 7 ++--
.../graphql/model/domain/GqlvDomainObject.java | 48 ++++++----------------
2 files changed, 17 insertions(+), 38 deletions(-)
diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAbstractCustom.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAbstractCustom.java
index 17e762136d..92a680d374 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAbstractCustom.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAbstractCustom.java
@@ -61,15 +61,16 @@ public abstract class GqlvAbstractCustom extends GqlvAbstract implements Parent
return gqlObjectType != null;
}
- protected final void addChildFieldFor(@Nullable GqlvAbstract hasField) {
+ protected final <T extends GqlvAbstract> T addChildFieldFor(@Nullable T hasField) {
if (isBuilt()) {
// the type was built already
- return;
+ return hasField;
}
if (hasField == null) {
- return;
+ return hasField;
}
addChildField(hasField.getField());
+ return hasField;
}
void addChildField(GraphQLFieldDefinition childField) {
diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
index f591fb5296..64f200eb2a 100644
--- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
+++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java
@@ -18,9 +18,8 @@
*/
package org.apache.causeway.viewer.graphql.model.domain;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
+import java.util.ArrayList;
+import java.util.List;
import graphql.Scalars;
import graphql.schema.DataFetchingEnvironment;
@@ -35,12 +34,8 @@ import static graphql.schema.GraphQLInputObjectType.newInputObject;
import org.apache.causeway.core.metamodel.spec.ActionScope;
import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
import org.apache.causeway.core.metamodel.spec.feature.MixedIn;
-import org.apache.causeway.core.metamodel.spec.feature.OneToManyAssociation;
-import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.causeway.viewer.graphql.model.context.Context;
-import graphql.schema.GraphQLList;
-
import lombok.Getter;
import lombok.val;
@@ -55,9 +50,9 @@ public class GqlvDomainObject
private final GqlvMeta meta;
- private final SortedMap<String, GqlvProperty> properties = new TreeMap<>();
- private final SortedMap<String, GqlvCollection> collections = new TreeMap<>();
- private final Map<String, GqlvAction> actions = new TreeMap<>();
+ private final List<GqlvProperty> properties = new ArrayList<>();
+ private final List<GqlvCollection> collections = new ArrayList<>();
+ private final List<GqlvAction> actions = new ArrayList<>();
@Getter private final GraphQLInputObjectType gqlInputObjectType;
@@ -131,15 +126,12 @@ public class GqlvDomainObject
private void addMembers() {
- objectSpecification.streamProperties(MixedIn.INCLUDED).forEach(this::addProperty);
- objectSpecification.streamCollections(MixedIn.INCLUDED).forEach(this::addCollection);
-
+ objectSpecification.streamProperties(MixedIn.INCLUDED)
+ .forEach(prop -> properties.add(addChildFieldFor(new GqlvProperty(this, prop, context))));
+ objectSpecification.streamCollections(MixedIn.INCLUDED)
+ .forEach(coll -> collections.add(addChildFieldFor(new GqlvCollection(this, coll, context))));
objectSpecification.streamActions(context.getActionScope(), MixedIn.INCLUDED)
- .forEach(objectAction -> {
- val gqlvAction = new GqlvAction(this, objectAction, context);
- addChildFieldFor(gqlvAction);
- actions.put(objectAction.getId(), gqlvAction);
- });
+ .forEach(act -> actions.add(addChildFieldFor(new GqlvAction(this, act, context))));
}
@SuppressWarnings("unused")
@@ -149,20 +141,6 @@ public class GqlvDomainObject
: ActionScope.PROTOTYPE;
}
- private void addProperty(final OneToOneAssociation otoa) {
- val gqlvProperty = new GqlvProperty(this, otoa, context);
- addChildFieldFor(gqlvProperty);
- properties.put(otoa.getId(), gqlvProperty);
- }
-
- private void addCollection(OneToManyAssociation otom) {
- val gqlvCollection = new GqlvCollection(this, otom, context);
- addChildFieldFor(gqlvCollection);
- if (gqlvCollection.isFieldDefined()) {
- collections.put(otom.getId(), gqlvCollection);
- }
- }
-
@Override
protected void addDataFetchersForChildren() {
@@ -170,9 +148,9 @@ public class GqlvDomainObject
return;
}
meta.addDataFetcher(this);
- properties.forEach((id, property) -> property.addDataFetcher(this));
- collections.forEach((id, collection) -> collection.addDataFetcher(this));
- actions.forEach((id, action) -> action.addDataFetcher(this));
+ properties.forEach(property -> property.addDataFetcher(this));
+ collections.forEach(collection -> collection.addDataFetcher(this));
+ actions.forEach(action -> action.addDataFetcher(this));
}
@Override