Skip to content

Commit

Permalink
Merge pull request #1347 from phillip-kruger/main
Browse files Browse the repository at this point in the history
Add built-in support for `org.bson.types.ObjectId`
  • Loading branch information
jmartisk authored Apr 8, 2022
2 parents b655a16 + 92e51cf commit 15385ae
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static Reference getIDScalar(String className) {
populateScalar(UUID.class.getName(), STRING, String.class.getName());
populateScalar(URL.class.getName(), STRING, String.class.getName());
populateScalar(URI.class.getName(), STRING, String.class.getName());
populateScalar("org.bson.types.ObjectId", STRING, String.class.getName());
populateScalar("javax.json.JsonObject", STRING, String.class.getName());
populateScalar("javax.json.JsonArray", STRING, String.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static boolean isGraphQLScalarType(String className) {

SCALAR_MAP.put(String.class.getName(), Scalars.GraphQLString);
SCALAR_MAP.put(UUID.class.getName(), Scalars.GraphQLString);
SCALAR_MAP.put("org.bson.types.ObjectId", Scalars.GraphQLString);
SCALAR_MAP.put(URL.class.getName(), Scalars.GraphQLString);
SCALAR_MAP.put(URI.class.getName(), Scalars.GraphQLString);

Expand Down
5 changes: 5 additions & 0 deletions server/runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
<artifactId>rxjava</artifactId>
<version>2.2.21</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.5.1</version>
</dependency>
<!-- The UI -->
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
7 changes: 6 additions & 1 deletion server/tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@
<version>2.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import java.net.URL;
import java.util.UUID;

import org.bson.types.ObjectId;

public class AdditionalScalars {
private URI uri;
private URL url;
private UUID uuid = UUID.fromString("037f4ba2-6d74-4686-a4ea-90cbd86007c3");
private ObjectId objectId = new ObjectId("624fbb9213b47a7f7afe1f89");

public AdditionalScalars() {
try {
Expand All @@ -31,4 +34,8 @@ public URL getUrl() {
public UUID getUuid() {
return uuid;
}

public ObjectId getObjectId() {
return objectId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.URL;
import java.util.UUID;

import org.bson.types.ObjectId;
import org.eclipse.microprofile.graphql.DefaultValue;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;
Expand All @@ -29,6 +30,10 @@ public UUID uuidInput(@Source AdditionalScalars additionalScalars, UUID uuid) {
return uuid;
}

public ObjectId objectIdInput(@Source AdditionalScalars additionalScalars, ObjectId objectId) {
return objectId;
}

public URL urlDefault(@Source AdditionalScalars additionalScalars, @DefaultValue("https://example.com") URL url) {
return url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
url
uri
uuid
objectId
urlInput(url:"https://example.com")
uriInput(uri:"https://example.com")
uuidInput(uuid:"037f4ba2-6d74-4686-a4ea-90cbd86007c3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"url": "https://example.com",
"uri": "https://example.com",
"uuid": "037f4ba2-6d74-4686-a4ea-90cbd86007c3",
"objectId": "624fbb9213b47a7f7afe1f89",
"urlInput": "https://example.com",
"uriInput": "https://example.com",
"uuidInput": "037f4ba2-6d74-4686-a4ea-90cbd86007c3",
Expand Down

0 comments on commit 15385ae

Please sign in to comment.