From 4dcd7b4f2b25cd2a4f938dd26a88d4462da7297e Mon Sep 17 00:00:00 2001 From: Jan Martiska Date: Thu, 2 Nov 2023 14:30:56 +0100 Subject: [PATCH] Option to register some scalars from graphql-java-extended-scalars --- .../java/io/smallrye/graphql/schema/model/Scalars.java | 8 +++++++- pom.xml | 7 +++++++ server/implementation/pom.xml | 5 +++++ .../io/smallrye/graphql/scalar/GraphQLScalarTypes.java | 6 ++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/common/schema-model/src/main/java/io/smallrye/graphql/schema/model/Scalars.java b/common/schema-model/src/main/java/io/smallrye/graphql/schema/model/Scalars.java index 2dc1feff0..901feab8c 100644 --- a/common/schema-model/src/main/java/io/smallrye/graphql/schema/model/Scalars.java +++ b/common/schema-model/src/main/java/io/smallrye/graphql/schema/model/Scalars.java @@ -94,6 +94,12 @@ public static Reference getIDScalar(String className) { .build(); } + // this is for the UUID from graphql-java-extended-scalars + // if used, it will override the original UUID type that is mapped to a String in the schema + public static void addUuid() { + populateScalar(UUID.class.getName(), "UUID", String.class.getName()); + } + static { // The main java type should go first. @@ -185,7 +191,7 @@ private static void populateScalar(String className, String scalarName, String e scalarMap.put(className, reference); // looking up by name - scalarNameMap.putIfAbsent(scalarName, reference); + scalarNameMap.put(scalarName, reference); //Currently, each scalar is formatted as String formattedScalarMap.put(className, new Reference.Builder() diff --git a/pom.xml b/pom.xml index ac9e199de..fff4bee87 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ 2.0.0 2.1.1 21.1 + 21.0 1.11.3 4.4.5 2.4.0 @@ -352,6 +353,12 @@ ${project.version} + + com.graphql-java + graphql-java-extended-scalars + ${version.extended-scalars} + + org.jboss.arquillian.container diff --git a/server/implementation/pom.xml b/server/implementation/pom.xml index 610d205aa..e14dee524 100644 --- a/server/implementation/pom.xml +++ b/server/implementation/pom.xml @@ -71,6 +71,11 @@ provided + + com.graphql-java + graphql-java-extended-scalars + + org.jboss.logging diff --git a/server/implementation/src/main/java/io/smallrye/graphql/scalar/GraphQLScalarTypes.java b/server/implementation/src/main/java/io/smallrye/graphql/scalar/GraphQLScalarTypes.java index 94bba5bb9..3f33f4180 100644 --- a/server/implementation/src/main/java/io/smallrye/graphql/scalar/GraphQLScalarTypes.java +++ b/server/implementation/src/main/java/io/smallrye/graphql/scalar/GraphQLScalarTypes.java @@ -7,6 +7,7 @@ import java.util.UUID; import graphql.Scalars; +import graphql.scalars.ExtendedScalars; import graphql.schema.GraphQLScalarType; import io.smallrye.graphql.scalar.number.BigDecimalScalar; import io.smallrye.graphql.scalar.number.BigIntegerScalar; @@ -46,6 +47,11 @@ public static boolean isGraphQLScalarType(String className) { return SCALAR_MAP.containsKey(className); } + public static void addUuid() { + SCALAR_MAP.put(UUID.class.getName(), ExtendedScalars.UUID); + SCALARS_BY_NAME.put(ExtendedScalars.UUID.getName(), ExtendedScalars.UUID); + } + // Scalar map we can just create now. private static final Map SCALAR_MAP = new HashMap<>();