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 f59dbc39737134b0f79a0c6222d026d82b005dd0 Author: danhaywood <[email protected]> AuthorDate: Wed Feb 21 22:12:07 2024 +0000 CAUSEWAY-3676: introduces RICH_AND_SCHEMA schema style --- .../core/config/CausewayConfiguration.java | 26 +++++++++++++--- .../graphql/model/src/main/java/module-info.java | 1 + .../mutation/GqlvTopLevelMutationRichSchema.java} | 8 ++--- ...chema.java => GqlvTopLevelQueryRichSchema.java} | 4 +-- .../GqlvTopLevelMutationSimpleSchema.java} | 8 ++--- ...ema.java => GqlvTopLevelQuerySimpleSchema.java} | 4 +-- ...Rich.java => GqlvTopLevelQueryBothSchemas.java} | 16 +++++----- .../integration/GraphQlSourceForCauseway.java | 35 +++++++++++++++++----- 8 files changed, 68 insertions(+), 34 deletions(-) diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java index 2dcc1afc51..850eaa0049 100644 --- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java +++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java @@ -2363,31 +2363,49 @@ public class CausewayConfiguration { * an action is hidden or disabled). * * <p> + * Optionally, fields for Scenario (given/when/then) testing may also be added if the + * {@link #isIncludeTestingFieldInRich()} config property is set. + * </p> + * <p> * Suitable for clients where the application logic and state remains in the backend, within the * domain model hosted by Causeway. * </p> */ RICH_ONLY, /** - * Exposes both the simple and rich schemas, with each under a field as defined by + * Exposes both the simple and rich schemas, for the query have each under a field as defined by * {@link #getTopLevelFieldNameForSimple()} (by default "simple") and * {@link #getTopLevelFieldNameForRich()} (by default "rich"). + * + * <p> + * For mutations, use the <i>simple</i> schema types. + * </p> */ SIMPLE_AND_RICH, + /** + * Exposes both the simple and rich schemas, for the query have each under a field as defined by + * {@link #getTopLevelFieldNameForSimple()} (by default "simple") and + * {@link #getTopLevelFieldNameForRich()} (by default "rich"). + * + * <p> + * For mutations, use the <i>rich</i> schema types. + * </p> + */ + RICH_AND_SIMPLE, ; public boolean isRich() { - return this == RICH_ONLY || this == SIMPLE_AND_RICH; + return this == RICH_ONLY || this == SIMPLE_AND_RICH || this == RICH_AND_SIMPLE; } public boolean isSimple() { - return this == SIMPLE_ONLY || this == SIMPLE_AND_RICH; + return this == SIMPLE_ONLY || this == SIMPLE_AND_RICH || this == RICH_AND_SIMPLE; } } /** * Which {@link SchemaStyle} to expose. */ - private SchemaStyle schemaStyle = SchemaStyle.SIMPLE_AND_RICH; + private SchemaStyle schemaStyle = SchemaStyle.RICH_AND_SIMPLE; /** * If the {@link #getSchemaStyle()} is set to {@link SchemaStyle#SIMPLE_AND_RICH}, defines the name of the diff --git a/viewers/graphql/model/src/main/java/module-info.java b/viewers/graphql/model/src/main/java/module-info.java index e8a219b7d7..3482f0d3a9 100644 --- a/viewers/graphql/model/src/main/java/module-info.java +++ b/viewers/graphql/model/src/main/java/module-info.java @@ -11,6 +11,7 @@ module org.apache.causeway.incubator.viewer.graphql.model { exports org.apache.causeway.viewer.graphql.model.domain.rich.query; exports org.apache.causeway.viewer.graphql.model.domain.rich.mutation; exports org.apache.causeway.viewer.graphql.model.domain.simple.query; + exports org.apache.causeway.viewer.graphql.model.domain.simple.mutation; requires org.apache.causeway.core.config; requires org.apache.causeway.incubator.viewer.graphql.applib; diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/mutation/GqlvTopLevelMutationRichSchema.java similarity index 90% copy from viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java copy to viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/mutation/GqlvTopLevelMutationRichSchema.java index 393289ebd5..c7782a8dc1 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/mutation/GqlvTopLevelMutationRichSchema.java @@ -1,4 +1,4 @@ -package org.apache.causeway.viewer.graphql.model.toplevel; +package org.apache.causeway.viewer.graphql.model.domain.rich.mutation; import java.util.ArrayList; import java.util.List; @@ -14,19 +14,17 @@ import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation; import org.apache.causeway.viewer.graphql.model.context.Context; import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; import org.apache.causeway.viewer.graphql.model.domain.Parent; -import org.apache.causeway.viewer.graphql.model.domain.rich.mutation.GqlvMutationForAction; -import org.apache.causeway.viewer.graphql.model.domain.rich.mutation.GqlvMutationForProperty; import lombok.val; -public class GqlvTopLevelMutation +public class GqlvTopLevelMutationRichSchema extends GqlvAbstractCustom implements Parent { private final List<GqlvMutationForAction> actions = new ArrayList<>(); private final List<GqlvMutationForProperty> properties = new ArrayList<>(); - public GqlvTopLevelMutation(final Context context) { + public GqlvTopLevelMutationRichSchema(final Context context) { super("Mutation", context); if (isBuilt()) { diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelRichSchema.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelQueryRichSchema.java similarity index 96% rename from viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelRichSchema.java rename to viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelQueryRichSchema.java index ad2302ef17..af7bf810b9 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelRichSchema.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/rich/query/GqlvTopLevelQueryRichSchema.java @@ -13,7 +13,7 @@ import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; import org.apache.causeway.viewer.graphql.model.domain.GqlvScenario; import org.apache.causeway.viewer.graphql.model.domain.Parent; -public class GqlvTopLevelRichSchema +public class GqlvTopLevelQueryRichSchema extends GqlvAbstractCustom implements Parent { @@ -24,7 +24,7 @@ public class GqlvTopLevelRichSchema private final GqlvScenario scenario; - public GqlvTopLevelRichSchema(final Context context) { + public GqlvTopLevelQueryRichSchema(final Context context) { super("RichSchema", context); graphqlConfiguration = context.causewayConfiguration.getViewer().getGraphql(); diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/mutation/GqlvTopLevelMutationSimpleSchema.java similarity index 90% rename from viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java rename to viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/mutation/GqlvTopLevelMutationSimpleSchema.java index 393289ebd5..35507cbd69 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelMutation.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/mutation/GqlvTopLevelMutationSimpleSchema.java @@ -1,4 +1,4 @@ -package org.apache.causeway.viewer.graphql.model.toplevel; +package org.apache.causeway.viewer.graphql.model.domain.simple.mutation; import java.util.ArrayList; import java.util.List; @@ -14,19 +14,17 @@ import org.apache.causeway.core.metamodel.spec.feature.OneToOneAssociation; import org.apache.causeway.viewer.graphql.model.context.Context; import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; import org.apache.causeway.viewer.graphql.model.domain.Parent; -import org.apache.causeway.viewer.graphql.model.domain.rich.mutation.GqlvMutationForAction; -import org.apache.causeway.viewer.graphql.model.domain.rich.mutation.GqlvMutationForProperty; import lombok.val; -public class GqlvTopLevelMutation +public class GqlvTopLevelMutationSimpleSchema extends GqlvAbstractCustom implements Parent { private final List<GqlvMutationForAction> actions = new ArrayList<>(); private final List<GqlvMutationForProperty> properties = new ArrayList<>(); - public GqlvTopLevelMutation(final Context context) { + public GqlvTopLevelMutationSimpleSchema(final Context context) { super("Mutation", context); if (isBuilt()) { diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelSimpleSchema.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelQuerySimpleSchema.java similarity index 96% rename from viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelSimpleSchema.java rename to viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelQuerySimpleSchema.java index 930212c62b..1e460fb4c7 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelSimpleSchema.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/simple/query/GqlvTopLevelQuerySimpleSchema.java @@ -13,7 +13,7 @@ import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; import org.apache.causeway.viewer.graphql.model.domain.GqlvScenario; import org.apache.causeway.viewer.graphql.model.domain.Parent; -public class GqlvTopLevelSimpleSchema +public class GqlvTopLevelQuerySimpleSchema extends GqlvAbstractCustom implements Parent { @@ -24,7 +24,7 @@ public class GqlvTopLevelSimpleSchema private final GqlvScenario scenario; - public GqlvTopLevelSimpleSchema(final Context context) { + public GqlvTopLevelQuerySimpleSchema(final Context context) { super("SimpleSchema", context); graphqlConfiguration = context.causewayConfiguration.getViewer().getGraphql(); diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelForSimpleAndRich.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelQueryBothSchemas.java similarity index 63% rename from viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelForSimpleAndRich.java rename to viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelQueryBothSchemas.java index 1781d88a79..c97d60f117 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelForSimpleAndRich.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/toplevel/GqlvTopLevelQueryBothSchemas.java @@ -4,19 +4,19 @@ import graphql.schema.DataFetchingEnvironment; import org.apache.causeway.viewer.graphql.model.context.Context; import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; -import org.apache.causeway.viewer.graphql.model.domain.rich.query.GqlvTopLevelRichSchema; -import org.apache.causeway.viewer.graphql.model.domain.simple.query.GqlvTopLevelSimpleSchema; +import org.apache.causeway.viewer.graphql.model.domain.rich.query.GqlvTopLevelQueryRichSchema; +import org.apache.causeway.viewer.graphql.model.domain.simple.query.GqlvTopLevelQuerySimpleSchema; -public class GqlvTopLevelForSimpleAndRich extends GqlvAbstractCustom { +public class GqlvTopLevelQueryBothSchemas extends GqlvAbstractCustom { - private final GqlvTopLevelRichSchema richSchema; - private final GqlvTopLevelSimpleSchema simpleSchema; + private final GqlvTopLevelQueryRichSchema richSchema; + private final GqlvTopLevelQuerySimpleSchema simpleSchema; - public GqlvTopLevelForSimpleAndRich(final Context context) { + public GqlvTopLevelQueryBothSchemas(final Context context) { super("SimpleAndRich", context); - addChildFieldFor(richSchema = new GqlvTopLevelRichSchema(context)); - addChildFieldFor(simpleSchema = new GqlvTopLevelSimpleSchema(context)); + addChildFieldFor(richSchema = new GqlvTopLevelQueryRichSchema(context)); + addChildFieldFor(simpleSchema = new GqlvTopLevelQuerySimpleSchema(context)); buildObjectType(); } diff --git a/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java b/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java index 7bf2e12026..7795cf510b 100644 --- a/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java +++ b/viewers/graphql/viewer/src/main/java/org/apache/causeway/viewer/graphql/viewer/integration/GraphQlSourceForCauseway.java @@ -24,7 +24,8 @@ import graphql.GraphQL; import graphql.execution.SimpleDataFetcherExceptionHandler; import graphql.schema.GraphQLSchema; -import org.apache.causeway.viewer.graphql.model.domain.simple.query.GqlvTopLevelSimpleSchema; +import org.apache.causeway.viewer.graphql.model.domain.simple.mutation.GqlvTopLevelMutationSimpleSchema; +import org.apache.causeway.viewer.graphql.model.domain.simple.query.GqlvTopLevelQuerySimpleSchema; import org.springframework.graphql.execution.GraphQlSource; import org.springframework.stereotype.Service; @@ -35,10 +36,10 @@ import org.apache.causeway.core.config.metamodel.specloader.IntrospectionMode; import org.apache.causeway.core.metamodel.specloader.SpecificationLoader; import org.apache.causeway.viewer.graphql.model.context.Context; import org.apache.causeway.viewer.graphql.model.domain.GqlvAbstractCustom; -import org.apache.causeway.viewer.graphql.model.domain.rich.query.GqlvTopLevelRichSchema; +import org.apache.causeway.viewer.graphql.model.domain.rich.query.GqlvTopLevelQueryRichSchema; import org.apache.causeway.viewer.graphql.model.registry.GraphQLTypeRegistry; -import org.apache.causeway.viewer.graphql.model.toplevel.GqlvTopLevelForSimpleAndRich; -import org.apache.causeway.viewer.graphql.model.toplevel.GqlvTopLevelMutation; +import org.apache.causeway.viewer.graphql.model.toplevel.GqlvTopLevelQueryBothSchemas; +import org.apache.causeway.viewer.graphql.model.domain.rich.mutation.GqlvTopLevelMutationRichSchema; import lombok.val; @@ -103,7 +104,7 @@ public class GraphQlSourceForCauseway implements GraphQlSource { } val topLevelQuery = determineTopLevelQueryFrom(graphqlConfiguration.getSchemaStyle()); - val topLevelMutation = new GqlvTopLevelMutation(context); + val topLevelMutation = determineTopLevelMutationFrom(graphqlConfiguration.getSchemaStyle()); topLevelQuery.addDataFetchers(); topLevelMutation.addDataFetchers(); @@ -124,11 +125,29 @@ public class GraphQlSourceForCauseway implements GraphQlSource { final CausewayConfiguration.Viewer.Graphql.SchemaStyle schemaStyle) { switch (schemaStyle) { case SIMPLE_ONLY: - return new GqlvTopLevelSimpleSchema(context); + return new GqlvTopLevelQuerySimpleSchema(context); case RICH_ONLY: - return new GqlvTopLevelRichSchema(context); + return new GqlvTopLevelQueryRichSchema(context); case SIMPLE_AND_RICH: - return new GqlvTopLevelForSimpleAndRich(context); + case RICH_AND_SIMPLE: + return new GqlvTopLevelQueryBothSchemas(context); + default: + // shouldn't happen + throw new IllegalStateException(String.format( + "Configured SchemaStyle '%s' not recognised", schemaStyle)); + } + } + private GqlvAbstractCustom determineTopLevelMutationFrom( + final CausewayConfiguration.Viewer.Graphql.SchemaStyle schemaStyle) { + switch (schemaStyle) { + case SIMPLE_ONLY: + return new GqlvTopLevelMutationSimpleSchema(context); + case RICH_ONLY: + return new GqlvTopLevelMutationRichSchema(context); + case SIMPLE_AND_RICH: + return new GqlvTopLevelMutationSimpleSchema(context); + case RICH_AND_SIMPLE: + return new GqlvTopLevelMutationRichSchema(context); default: // shouldn't happen throw new IllegalStateException(String.format(
