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 7b6568c38e CAUSEWAY-3676: uses name of enum rather than their
toString()
7b6568c38e is described below
commit 7b6568c38e4215fd7e61aae96019fe0d4a0062b0
Author: danhaywood <[email protected]>
AuthorDate: Fri Feb 23 17:03:48 2024 +0000
CAUSEWAY-3676: uses name of enum rather than their toString()
---
.../viewer/graphql/model/registry/GraphQLTypeRegistry.java | 7 +++++--
.../causeway/viewer/graphql/viewer/test/domain/calc/Month.java | 4 ++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/registry/GraphQLTypeRegistry.java
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/registry/GraphQLTypeRegistry.java
index 518cd40857..c7eef8fa28 100644
---
a/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/registry/GraphQLTypeRegistry.java
+++
b/viewers/graphql/model/src/main/java/org/apache/causeway/viewer/graphql/model/registry/GraphQLTypeRegistry.java
@@ -81,14 +81,17 @@ public class GraphQLTypeRegistry {
val objectSpec =
contextProvider.get().specificationLoader.loadSpecification(typeToAdd);
val typeName = TypeNames.enumTypeNameFor(objectSpec, schemaType);
val enumTypeIfAny = lookup(typeName, GraphQLEnumType.class);
+
if (enumTypeIfAny.isPresent()) {
return enumTypeIfAny.get();
}
+
+ val enumTypeToAdd = (Class<? extends Enum<?>>) typeToAdd;
val enumType = newEnum()
.name(typeName)
- .values(Stream.of(typeToAdd.getEnumConstants())
+ .values(Stream.of(enumTypeToAdd.getEnumConstants())
.map(enumValue -> newEnumValueDefinition()
- .name(enumValue.toString())
+ .name(enumValue.name())
.value(enumValue)
.build()).collect(Collectors.toList())
)
diff --git
a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/calc/Month.java
b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/calc/Month.java
index 1aae20a304..c18ab87074 100644
---
a/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/calc/Month.java
+++
b/viewers/graphql/test/src/test/java/org/apache/causeway/viewer/graphql/viewer/test/domain/calc/Month.java
@@ -20,4 +20,8 @@ public enum Month {
int nextMonthOrdinal = (currentMonthOrdinal + 1) %
Month.values().length;
return Month.values()[nextMonthOrdinal];
}
+
+ public String toString() {
+ return "Month of " + ("" + name().charAt(0)).toUpperCase() +
(name().substring(1).toLowerCase());
+ }
}
\ No newline at end of file