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 36d95fadcf CAUSEWAY-3676: inlines QueryFieldFactory into
GraphQlSourceForCauseway
36d95fadcf is described below
commit 36d95fadcf7fab72f9e03b5962156ca05415ded1
Author: danhaywood <[email protected]>
AuthorDate: Sat Jan 20 10:50:55 2024 +0000
CAUSEWAY-3676: inlines QueryFieldFactory into GraphQlSourceForCauseway
---
.../integration/GraphQlSourceForCauseway.java | 44 +++++++++++++++++++++-
.../graphql/viewer/source/QueryFieldFactory.java | 35 -----------------
2 files changed, 43 insertions(+), 36 deletions(-)
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 04bf05a298..5c24c29be4 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,6 +23,8 @@ 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;
@@ -31,6 +33,9 @@ import org.apache.causeway.applib.id.HasLogicalType;
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.GqlvDomainService;
import org.apache.causeway.viewer.graphql.viewer.source.GqlvTopLevelQuery;
import org.apache.causeway.viewer.graphql.model.registry.GraphQLTypeRegistry;
import org.apache.causeway.viewer.graphql.viewer.source.ObjectTypeFactory;
@@ -129,7 +134,7 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
case MANAGED_BEAN_CONTRIBUTING: // @DomainService
-
queryFieldFactory.queryFieldFromObjectSpecification(objectSpec,
gqlvTopLevelQuery, codeRegistryBuilder);
+ addServiceToTopLevelQuery(objectSpec, gqlvTopLevelQuery,
codeRegistryBuilder);
break;
case ABSTRACT:
@@ -150,4 +155,41 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
break;
}
}
+
+ public void addServiceToTopLevelQuery(
+ final ObjectSpecification objectSpec,
+ final GqlvTopLevelQuery topLevelQueryStructure,
+ final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
+
+ serviceRegistry.lookupBeanById(objectSpec.getLogicalTypeName())
+ .ifPresent(service -> {
+ addServiceToTopLevelQuery(service, objectSpec,
topLevelQueryStructure, codeRegistryBuilder);
+ });
+ }
+
+ private void addServiceToTopLevelQuery(
+ final Object service,
+ final ObjectSpecification objectSpec,
+ final GqlvTopLevelQuery topLevelQueryStructure,
+ final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
+
+ val domainService = new GqlvDomainService(objectSpec, service,
codeRegistryBuilder, specificationLoader);
+
+ List<ObjectAction> objectActionList =
objectSpec.streamRuntimeActions(MixedIn.INCLUDED)
+ .map(ObjectAction.class::cast)
+ .collect(Collectors.toList());
+
+ if (objectActionList.isEmpty()) {
+ return;
+ }
+
+ objectActionList.forEach(domainService::addAction);
+
+ domainService.buildObjectGqlType();
+
+ domainService.getSafeActions().forEach(domainService::addDataFetcher);
+
+ topLevelQueryStructure.addFieldFor(domainService, codeRegistryBuilder);
+ }
+
}
diff --git
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/QueryFieldFactory.java
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/QueryFieldFactory.java
index fc765568cc..724df42b07 100644
---
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/QueryFieldFactory.java
+++
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/QueryFieldFactory.java
@@ -48,40 +48,5 @@ public class QueryFieldFactory {
private final ServiceRegistry serviceRegistry;
private final SpecificationLoader specificationLoader;
- public void queryFieldFromObjectSpecification(
- final ObjectSpecification objectSpec,
- final GqlvTopLevelQuery topLevelQueryStructure,
- final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
-
- serviceRegistry.lookupBeanById(objectSpec.getLogicalTypeName())
- .ifPresent(service -> {
- addService(objectSpec, service, topLevelQueryStructure,
codeRegistryBuilder);
- });
- }
-
- private void addService(
- final ObjectSpecification serviceSpec,
- final Object service,
- final GqlvTopLevelQuery topLevelQueryStructure,
- final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
-
- val domainService = new GqlvDomainService(serviceSpec, service,
codeRegistryBuilder, specificationLoader);
-
- List<ObjectAction> objectActionList =
serviceSpec.streamRuntimeActions(MixedIn.INCLUDED)
- .map(ObjectAction.class::cast)
- .collect(Collectors.toList());
-
- if (objectActionList.isEmpty()) {
- return;
- }
-
- objectActionList.forEach(domainService::addAction);
-
- domainService.buildObjectGqlType();
-
- domainService.getSafeActions().forEach(domainService::addDataFetcher);
-
- topLevelQueryStructure.addFieldFor(domainService, codeRegistryBuilder);
- }
}