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 05a245e707 CAUSEWAY-3676: combines GqlvTopLevelStructure and Behaviour
05a245e707 is described below
commit 05a245e70719bd4a28b8b3f291eb8641a14d5f34
Author: danhaywood <[email protected]>
AuthorDate: Sat Jan 20 10:47:05 2024 +0000
CAUSEWAY-3676: combines GqlvTopLevelStructure and Behaviour
---
.../integration/GraphQlSourceForCauseway.java | 19 ++++++-------
...lQueryStructure.java => GqlvTopLevelQuery.java} | 21 ++++++++++++--
.../viewer/source/GqlvTopLevelQueryBehaviour.java | 32 ----------------------
.../graphql/viewer/source/QueryFieldFactory.java | 5 ++--
4 files changed, 29 insertions(+), 48 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 1a8d8af08f..04bf05a298 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
@@ -31,8 +31,7 @@ import org.apache.causeway.applib.id.HasLogicalType;
import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
-import
org.apache.causeway.viewer.graphql.viewer.source.GqlvTopLevelQueryBehaviour;
-import
org.apache.causeway.viewer.graphql.viewer.source.GqlvTopLevelQueryStructure;
+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;
import org.apache.causeway.viewer.graphql.viewer.source.QueryFieldFactory;
@@ -97,19 +96,17 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
// add to the top-level query
// (and also add behaviour to the child types)
- val topLevelQueryStructure = new GqlvTopLevelQueryStructure();
+ val topLevelQuery = new GqlvTopLevelQuery(serviceRegistry,
codeRegistryBuilder);
specificationLoader.snapshotSpecifications()
.distinct((a, b) ->
a.getLogicalTypeName().equals(b.getLogicalTypeName()))
.sorted(Comparator.comparing(HasLogicalType::getLogicalTypeName))
- .forEach(objectSpec -> addToSchema(objectSpec,
topLevelQueryStructure, codeRegistryBuilder));
+ .forEach(objectSpec -> addToSchema(objectSpec, topLevelQuery,
codeRegistryBuilder));
- topLevelQueryStructure.buildQueryType();
+ topLevelQuery.buildQueryType();
- // add behaviour to the top-level query's own fields
- val topLevelQueryBehaviour = new
GqlvTopLevelQueryBehaviour(topLevelQueryStructure, codeRegistryBuilder,
serviceRegistry);
- topLevelQueryBehaviour.addFetchers();
+ topLevelQuery.addFetchers();
// finalize the fetcher/mutator code that's been registered
val codeRegistry = codeRegistryBuilder.build();
@@ -117,7 +114,7 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
// build the schema
return GraphQLSchema.newSchema()
- .query(topLevelQueryStructure.getQueryType())
+ .query(topLevelQuery.getQueryType())
.additionalTypes(graphQLTypeRegistry.getGraphQLObjectTypes())
.codeRegistry(codeRegistry)
.build();
@@ -125,14 +122,14 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
private void addToSchema(
final ObjectSpecification objectSpec,
- final GqlvTopLevelQueryStructure gqlvTopLevelQueryStructure,
+ final GqlvTopLevelQuery gqlvTopLevelQuery,
final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
switch (objectSpec.getBeanSort()) {
case MANAGED_BEAN_CONTRIBUTING: // @DomainService
-
queryFieldFactory.queryFieldFromObjectSpecification(objectSpec,
gqlvTopLevelQueryStructure, codeRegistryBuilder);
+
queryFieldFactory.queryFieldFromObjectSpecification(objectSpec,
gqlvTopLevelQuery, codeRegistryBuilder);
break;
case ABSTRACT:
diff --git
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryStructure.java
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQuery.java
similarity index 71%
rename from
incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryStructure.java
rename to
incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQuery.java
index 5f92481406..1c4d84c445 100644
---
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryStructure.java
+++
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQuery.java
@@ -9,12 +9,17 @@ import graphql.schema.GraphQLObjectType;
import lombok.Getter;
+import org.apache.causeway.applib.services.registry.ServiceRegistry;
import org.apache.causeway.viewer.graphql.model.domain.GqlvDomainService;
+import static graphql.schema.FieldCoordinates.coordinates;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLObjectType.newObject;
-public class GqlvTopLevelQueryStructure {
+public class GqlvTopLevelQuery {
+
+ private final ServiceRegistry serviceRegistry;
+ private final GraphQLCodeRegistry.Builder codeRegistryBuilder;
@Getter final GraphQLObjectType.Builder queryBuilder;
@@ -26,7 +31,11 @@ public class GqlvTopLevelQueryStructure {
private GraphQLObjectType queryType;
- public GqlvTopLevelQueryStructure() {
+ public GqlvTopLevelQuery(
+ final ServiceRegistry serviceRegistry,
+ final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
+ this.serviceRegistry = serviceRegistry;
+ this.codeRegistryBuilder = codeRegistryBuilder;
queryBuilder = newObject().name("Query");
numServicesField = newFieldDefinition()
@@ -69,4 +78,12 @@ public class GqlvTopLevelQueryStructure {
(DataFetcher<Object>) environment -> domainService.getPojo());
}
+
+ public void addFetchers() {
+ codeRegistryBuilder
+ .dataFetcher(
+ coordinates(getQueryType(), getNumServicesField()),
+ (DataFetcher<Object>) environment ->
this.serviceRegistry.streamRegisteredBeans().count());
+ }
+
}
diff --git
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryBehaviour.java
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryBehaviour.java
deleted file mode 100644
index d09c3a4398..0000000000
---
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/source/GqlvTopLevelQueryBehaviour.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.apache.causeway.viewer.graphql.viewer.source;
-
-import graphql.schema.DataFetcher;
-import graphql.schema.GraphQLCodeRegistry;
-
-import org.apache.causeway.applib.services.registry.ServiceRegistry;
-
-import static graphql.schema.FieldCoordinates.coordinates;
-
-public class GqlvTopLevelQueryBehaviour {
-
- private final GqlvTopLevelQueryStructure structure;
- private final GraphQLCodeRegistry.Builder codeRegistryBuilder;
- private final ServiceRegistry serviceRegistry;
-
- public GqlvTopLevelQueryBehaviour(
- final GqlvTopLevelQueryStructure structure,
- final GraphQLCodeRegistry.Builder codeRegistryBuilder,
- final ServiceRegistry serviceRegistry) {
- this.structure = structure;
- this.codeRegistryBuilder = codeRegistryBuilder;
- this.serviceRegistry = serviceRegistry;
- }
-
- public void addFetchers() {
- codeRegistryBuilder
- .dataFetcher(
- coordinates(structure.getQueryType(),
structure.getNumServicesField()),
- (DataFetcher<Object>) environment ->
this.serviceRegistry.streamRegisteredBeans().count());
- }
-
-}
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 aec733d5de..fc765568cc 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
@@ -45,13 +45,12 @@ import lombok.val;
@RequiredArgsConstructor(onConstructor_ = {@Inject})
public class QueryFieldFactory {
- private static ObjectAction objectAction;
private final ServiceRegistry serviceRegistry;
private final SpecificationLoader specificationLoader;
public void queryFieldFromObjectSpecification(
final ObjectSpecification objectSpec,
- final GqlvTopLevelQueryStructure topLevelQueryStructure,
+ final GqlvTopLevelQuery topLevelQueryStructure,
final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
serviceRegistry.lookupBeanById(objectSpec.getLogicalTypeName())
@@ -63,7 +62,7 @@ public class QueryFieldFactory {
private void addService(
final ObjectSpecification serviceSpec,
final Object service,
- final GqlvTopLevelQueryStructure topLevelQueryStructure,
+ final GqlvTopLevelQuery topLevelQueryStructure,
final GraphQLCodeRegistry.Builder codeRegistryBuilder) {
val domainService = new GqlvDomainService(serviceSpec, service,
codeRegistryBuilder, specificationLoader);