Skip to content

Commit

Permalink
Option to register some scalars from graphql-java-extended-scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Nov 10, 2023
1 parent aa28d9a commit 4dcd7b4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<version.jakarta.websocket>2.0.0</version.jakarta.websocket>
<version.graphql-java-federation>2.1.1</version.graphql-java-federation>
<version.graphql-java>21.1</version.graphql-java>
<version.extended-scalars>21.0</version.extended-scalars>
<verison.io.micrometer>1.11.3</verison.io.micrometer>
<version.vertx>4.4.5</version.vertx>
<version.smallrye-opentelemetry>2.4.0</version.smallrye-opentelemetry>
Expand Down Expand Up @@ -352,6 +353,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-scalars</artifactId>
<version>${version.extended-scalars}</version>
</dependency>

<!-- Tests -->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
Expand Down
5 changes: 5 additions & 0 deletions server/implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-scalars</artifactId>
</dependency>

<!-- i18n -->
<dependency>
<groupId>org.jboss.logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, GraphQLScalarType> SCALAR_MAP = new HashMap<>();

Expand Down

0 comments on commit 4dcd7b4

Please sign in to comment.