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 8b22033f6feadff159574c1bd7b545c754a090c7 Author: danhaywood <[email protected]> AuthorDate: Wed Jan 31 13:14:51 2024 +0000 CAUSEWAY-3676 : don't suppress entire non-idempotent action, only the invoke --- .../viewer/graphql/model/domain/GqlvAction.java | 20 ++++++++++++++++---- .../graphql/model/domain/GqlvDomainObject.java | 4 ---- .../graphql/model/domain/GqlvDomainService.java | 4 ---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java index 8308b47c55..814f19a173 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvAction.java @@ -32,11 +32,14 @@ import graphql.schema.GraphQLObjectType; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLObjectType.newObject; +import static org.apache.causeway.core.config.CausewayConfiguration.Viewer.Graphql.ApiVariant.QUERY_WITH_MUTATIONS_NON_SPEC_COMPLIANT; + import org.apache.causeway.applib.services.bookmark.Bookmark; import org.apache.causeway.applib.services.bookmark.BookmarkService; import org.apache.causeway.commons.collections.Can; import org.apache.causeway.core.metamodel.object.ManagedObject; 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.core.metamodel.spec.feature.ObjectActionParameter; import org.apache.causeway.core.metamodel.spec.feature.OneToManyActionParameter; @@ -63,6 +66,9 @@ public class GqlvAction private final GqlvMemberHidden<ObjectAction> hidden; private final GqlvMemberDisabled<ObjectAction> disabled; private final GqlvActionValidity validate; + /** + * Populated iff the API variant allows for it. + */ private final GqlvActionInvoke invoke; /** * Populated iif there are params for this action. @@ -80,7 +86,11 @@ public class GqlvAction this.hidden = new GqlvMemberHidden<>(this, context); this.disabled = new GqlvMemberDisabled<>(this, context); this.validate = new GqlvActionValidity(this, context); - this.invoke = new GqlvActionInvoke(this, context); + + val variant = context.causewayConfiguration.getViewer().getGraphql().getApiVariant(); + this.invoke = objectAction.getSemantics().isSafeInNature() || variant == QUERY_WITH_MUTATIONS_NON_SPEC_COMPLIANT + ? new GqlvActionInvoke(this, context) + : null; val params = new GqlvActionParams(this, context); this.params = params.hasParams() ? params : null; @@ -157,14 +167,14 @@ public class GqlvAction private static ManagedObject adaptValue( final ObjectActionParameter oap, final Object argumentValue, - final Context context1) { + final Context context) { val elementType = oap.getElementType(); if (argumentValue == null) { return ManagedObject.empty(elementType); } - val argPojo = context1.typeMapper.adaptPojo(argumentValue, elementType); + val argPojo = context.typeMapper.adaptPojo(argumentValue, elementType); return ManagedObject.adaptParameter(oap, argPojo); } @@ -250,7 +260,9 @@ public class GqlvAction hidden.addDataFetcher(); disabled.addDataFetcher(); validate.addDataFetcher(); - invoke.addDataFetcher(); + if (invoke != null) { + invoke.addDataFetcher(); + } if (params != null) { params.addDataFetcher(); } diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java index 1416c7326c..10c1ab2491 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainObject.java @@ -104,11 +104,7 @@ public class GqlvDomainObject implements GqlvAction.Holder, GqlvProperty.Holder, objectSpecification.streamProperties(MixedIn.INCLUDED).forEach(this::addProperty); objectSpecification.streamCollections(MixedIn.INCLUDED).forEach(this::addCollection); - val variant = context.causewayConfiguration.getViewer().getGraphql().getApiVariant(); - objectSpecification.streamActions(context.getActionScope(), MixedIn.INCLUDED) - .filter(x -> x.getSemantics().isSafeInNature() || - variant == QUERY_WITH_MUTATIONS_NON_SPEC_COMPLIANT) .forEach(objectAction -> { actions.put(objectAction.getId(), new GqlvAction(this, objectAction, context)); }); diff --git a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java index de9d07a760..0ba21a2d94 100644 --- a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java +++ b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvDomainService.java @@ -85,11 +85,7 @@ public class GqlvDomainService implements GqlvAction.Holder { private void addActions() { - val variant = context.causewayConfiguration.getViewer().getGraphql().getApiVariant(); - objectSpecification.streamActions(context.getActionScope(), MixedIn.INCLUDED) - .filter(x -> x.getSemantics().isSafeInNature() || - variant == QUERY_WITH_MUTATIONS_NON_SPEC_COMPLIANT) .forEach(this::addAction); }
