-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added fix for non-necessary json transformation for ObjectId argument…
… value
- Loading branch information
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...r/integration-tests/src/test/java/io/smallrye/graphql/tests/objectid/ObjectIdAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.smallrye.graphql.tests.objectid; | ||
|
||
import org.bson.types.ObjectId; | ||
|
||
import io.smallrye.graphql.api.Adapter; | ||
|
||
public class ObjectIdAdapter implements Adapter<ObjectId, String> { | ||
@Override | ||
public ObjectId from(String o) { | ||
return new ObjectId(o); | ||
} | ||
|
||
@Override | ||
public String to(ObjectId a) throws Exception { | ||
return a.toHexString(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
server/integration-tests/src/test/java/io/smallrye/graphql/tests/objectid/ObjectIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.smallrye.graphql.tests.objectid; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.net.URL; | ||
|
||
import org.bson.types.ObjectId; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.smallrye.graphql.tests.GraphQLAssured; | ||
|
||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class ObjectIdTest { | ||
|
||
@Deployment | ||
public static WebArchive deployment() { | ||
return ShrinkWrap.create(WebArchive.class, "objectId-test.war") | ||
.addClasses(SomeApi.class, ObjectIdAdapter.class); | ||
} | ||
|
||
@ArquillianResource | ||
URL testingURL; | ||
|
||
@Test | ||
public void queryWithObjectIdArgumentTest() { | ||
final String id = ObjectId.get().toHexString(); | ||
System.err.println(id); | ||
GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); | ||
|
||
String response = graphQLAssured | ||
.post("{ returnObjectId(id: \"" + id + "\") }"); | ||
assertThat(response).contains("{\"data\":{\"returnObjectId\":\"" + id + "\"}}"); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
server/integration-tests/src/test/java/io/smallrye/graphql/tests/objectid/SomeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.smallrye.graphql.tests.objectid; | ||
|
||
import org.bson.types.ObjectId; | ||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Query; | ||
|
||
import io.smallrye.graphql.api.AdaptWith; | ||
|
||
@GraphQLApi | ||
public class SomeApi { | ||
@Query | ||
public @AdaptWith(ObjectIdAdapter.class) ObjectId returnObjectId(@AdaptWith(ObjectIdAdapter.class) ObjectId id) { | ||
return id; | ||
} | ||
|
||
} |