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 a07fbc9adbe77d87f50afd9560df6f2a37de6950 Author: danhaywood <[email protected]> AuthorDate: Fri Jan 26 17:35:34 2024 +0000 CAUSEWAY-3676: allows the name of the _gqlv_meta field to be customised --- .../org/apache/causeway/core/config/CausewayConfiguration.java | 8 +++++--- .../org/apache/causeway/viewer/graphql/model/context/Context.java | 2 ++ .../org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java | 2 +- .../graphql/viewer/integration/GraphQlSourceForCauseway.java | 2 +- 4 files changed, 9 insertions(+), 5 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 5700aa3563..6e97b34add 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 @@ -2349,9 +2349,11 @@ public class CausewayConfiguration { private final MetaData metaData = new MetaData(); @Data public static class MetaData { - private String idAttributeName = "__id"; - private String logicalTypeNameAttributeName = "__type"; - private String versionAttributeName = "__version"; + /** + * Note that field names <i>cannot</i> being with "__", as that is reserved by the + * underlying GraphQL implementation. + */ + private String fieldName = "_gqlv_meta"; } private final TypeMapper typeMapper = new TypeMapper(); diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/context/Context.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/context/Context.java index 325ac6e3dc..9f985b6c61 100644 --- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/context/Context.java +++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/context/Context.java @@ -23,6 +23,7 @@ import graphql.schema.GraphQLCodeRegistry; import lombok.RequiredArgsConstructor; import org.apache.causeway.applib.services.bookmark.BookmarkService; +import org.apache.causeway.core.config.CausewayConfiguration; import org.apache.causeway.core.metamodel.specloader.SpecificationLoader; import org.apache.causeway.viewer.graphql.model.types.TypeMapper; @@ -35,4 +36,5 @@ public class Context { public final BookmarkService bookmarkService; public final SpecificationLoader specificationLoader; public final TypeMapper typeMapper; + public final CausewayConfiguration causewayConfiguration; } diff --git a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java index 4db1d23b85..1b6f85cac1 100644 --- a/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java +++ b/incubator/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/domain/GqlvMeta.java @@ -73,7 +73,7 @@ public class GqlvMeta { if (this.holder.getObjectSpecification().getBeanSort() == BeanSort.ENTITY) { metaTypeBuilder.field(version); } - metaField = newFieldDefinition().name("_gqlv_meta").type(metaTypeBuilder.build()).build(); + metaField = newFieldDefinition().name(context.causewayConfiguration.getViewer().getGqlv().getMetaData().getFieldName()).type(metaTypeBuilder.build()).build(); holder.addField(metaField); } 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 5252488929..0fb0a2f843 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 @@ -148,7 +148,7 @@ public class GraphQlSourceForCauseway implements GraphQlSource { final GqlvTopLevelQuery gqlvTopLevelQuery, final GraphQLCodeRegistry.Builder codeRegistryBuilder) { - Context context = new Context(codeRegistryBuilder, bookmarkService, specificationLoader, typeMapper); + Context context = new Context(codeRegistryBuilder, bookmarkService, specificationLoader, typeMapper, causewayConfiguration); switch (objectSpec.getBeanSort()) {
