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 a574eece43 CAUSEWAY-3676: factors GqlvTopLevelQueryStructure and
Behaviour
a574eece43 is described below
commit a574eece434b6e754b4969a10713605529dec888
Author: danhaywood <[email protected]>
AuthorDate: Fri Jan 19 15:43:28 2024 +0000
CAUSEWAY-3676: factors GqlvTopLevelQueryStructure and Behaviour
---
.../integration/GqlvTopLevelQueryBehaviour.java | 30 ++++++++++++++++++++++
.../integration/GraphQlSourceForCauseway.java | 21 +++++----------
2 files changed, 37 insertions(+), 14 deletions(-)
diff --git
a/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GqlvTopLevelQueryBehaviour.java
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GqlvTopLevelQueryBehaviour.java
new file mode 100644
index 0000000000..7ac8b4b26e
--- /dev/null
+++
b/incubator/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GqlvTopLevelQueryBehaviour.java
@@ -0,0 +1,30 @@
+package org.apache.causeway.viewer.graphql.viewer.integration;
+
+import graphql.schema.DataFetcher;
+import graphql.schema.GraphQLCodeRegistry;
+
+import org.apache.causeway.applib.services.registry.ServiceRegistry;
+import
org.apache.causeway.viewer.graphql.viewer.source.GqlvTopLevelQueryStructure;
+
+import static graphql.schema.FieldCoordinates.coordinates;
+
+public class GqlvTopLevelQueryBehaviour {
+
+ private final GqlvTopLevelQueryStructure topLevelQueryStructure;
+ private final ServiceRegistry serviceRegistry;
+
+ public GqlvTopLevelQueryBehaviour(
+ final GqlvTopLevelQueryStructure topLevelQueryStructure,
+ final ServiceRegistry serviceRegistry) {
+ this.topLevelQueryStructure = topLevelQueryStructure;
+ this.serviceRegistry = serviceRegistry;
+ }
+
+ public void addFetchersTo(GraphQLCodeRegistry.Builder codeRegistryBuilder)
{
+ codeRegistryBuilder
+ .dataFetcher(
+ coordinates(topLevelQueryStructure.getQueryType(),
topLevelQueryStructure.getNumServicesField()),
+ (DataFetcher<Object>) environment ->
this.serviceRegistry.streamRegisteredBeans().count());
+
+ }
+}
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 3ad6fec9dd..4482c39756 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
@@ -46,11 +46,7 @@ import
org.apache.causeway.core.config.metamodel.specloader.IntrospectionMode;
import org.apache.causeway.core.metamodel.specloader.SpecificationLoader;
import graphql.GraphQL;
-import graphql.Scalars;
-import graphql.schema.DataFetcher;
import graphql.schema.GraphQLCodeRegistry;
-import graphql.schema.GraphQLFieldDefinition;
-import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;
import lombok.RequiredArgsConstructor;
@@ -97,24 +93,22 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
final GraphQLCodeRegistry.Builder codeRegistryBuilder =
GraphQLCodeRegistry.newCodeRegistry();
- val gqlvTopLevelQueryStructure = new GqlvTopLevelQueryStructure();
+ val topLevelQueryStructure = new GqlvTopLevelQueryStructure();
specificationLoader.snapshotSpecifications()
.distinct((a, b) ->
a.getLogicalTypeName().equals(b.getLogicalTypeName()))
.sorted(Comparator.comparing(HasLogicalType::getLogicalTypeName))
- .forEach(objectSpec -> addToSchema(objectSpec,
codeRegistryBuilder, gqlvTopLevelQueryStructure));
+ .forEach(objectSpec -> addToSchema(objectSpec,
topLevelQueryStructure, codeRegistryBuilder));
+ topLevelQueryStructure.buildQueryType();
- GraphQLObjectType queryType =
gqlvTopLevelQueryStructure.buildQueryType();
+ val topLevelQueryBehaviour = new
GqlvTopLevelQueryBehaviour(topLevelQueryStructure, serviceRegistry);
+ topLevelQueryBehaviour.addFetchersTo(codeRegistryBuilder);
- codeRegistryBuilder
- .dataFetcher(
- coordinates(queryType,
gqlvTopLevelQueryStructure.getNumServicesField()),
- (DataFetcher<Object>) environment ->
this.serviceRegistry.streamRegisteredBeans().count());
val codeRegistry = codeRegistryBuilder.build();
return GraphQLSchema.newSchema()
- .query(queryType)
+ .query(topLevelQueryStructure.getQueryType())
.additionalTypes(graphQLTypeRegistry.getGraphQLObjectTypes())
.codeRegistry(codeRegistry)
.build();
@@ -122,8 +116,7 @@ public class GraphQlSourceForCauseway implements
GraphQlSource {
private void addToSchema(
final ObjectSpecification objectSpec,
- final GraphQLCodeRegistry.Builder codeRegistryBuilder,
- final GqlvTopLevelQueryStructure gqlvTopLevelQueryStructure) {
+ final GqlvTopLevelQueryStructure gqlvTopLevelQueryStructure, final
GraphQLCodeRegistry.Builder codeRegistryBuilder) {
switch (objectSpec.getBeanSort()) {