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 5d611e73c24e1be4c2142897573e92e1eb259a48 Author: danhaywood <[email protected]> AuthorDate: Sat Jan 20 19:17:33 2024 +0000 introduces addActions on GqlvDomainService --- .../viewer/graphql/model/domain/GqlvDomainService.java | 14 ++++++++++++++ .../viewer/integration/GraphQlSourceForCauseway.java | 16 ++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java index 9bb7fea2da..1cc57e783e 100644 --- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java +++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.stream.Collectors; 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.ObjectAction; import org.apache.causeway.viewer.graphql.model.util._LTN; import org.apache.causeway.viewer.graphql.model.types.TypeMapper; @@ -93,5 +94,18 @@ public class GqlvDomainService implements GqlvActionHolder, GqlvMutatorsHolder { } + /** + * @return <code>true</code> if any (at least one) actions were added + */ + public boolean addActions() { + List<ObjectAction> objectActionList = getObjectSpecification().streamRuntimeActions(MixedIn.INCLUDED) + .map(ObjectAction.class::cast) + .collect(Collectors.toList()); + + objectActionList.forEach(this::addAction); + + + return !objectActionList.isEmpty(); + } } diff --git a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java index 6a815581b3..a3dc60c3bb 100644 --- a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java +++ b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java @@ -23,8 +23,6 @@ import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLObjectType.newObject; import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -35,8 +33,7 @@ import org.apache.causeway.applib.services.bookmark.BookmarkService; import org.apache.causeway.core.metamodel.objectmanager.ObjectManager; 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.ObjectAction; +import org.apache.causeway.viewer.graphql.model.domain.GqlvAction; import org.apache.causeway.viewer.graphql.model.domain.GqlvDomainObject; import org.apache.causeway.viewer.graphql.model.domain.GqlvDomainService; import org.apache.causeway.viewer.graphql.viewer.toplevel.GqlvTopLevelQuery; @@ -174,19 +171,14 @@ public class GraphQlSourceForCauseway implements GraphQlSource { val domainService = new GqlvDomainService(objectSpec, service, codeRegistryBuilder); - List<ObjectAction> objectActionList = objectSpec.streamRuntimeActions(MixedIn.INCLUDED) - .map(ObjectAction.class::cast) - .collect(Collectors.toList()); - - if (objectActionList.isEmpty()) { + boolean actionsAdded = domainService.addActions(); + if (!actionsAdded) { return; } - objectActionList.forEach(domainService::addAction); - domainService.buildObjectGqlType(); - domainService.getSafeActions().forEach(gqlvAction -> gqlvAction.addDataFetcher()); + domainService.getSafeActions().forEach(GqlvAction::addDataFetcher); topLevelQueryStructure.addFieldFor(domainService, codeRegistryBuilder); }
