Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additional test coverage related to SmallRye GraphQL 1.5 #25451

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion extensions/smallrye-graphql-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<artifactId>quarkus-smallrye-graphql-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-discovery-static-list</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -74,4 +79,4 @@
</build>


</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.smallrye.graphql.client.deployment;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import javax.inject.Inject;

import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.smallrye.graphql.client.deployment.model.Person;
import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLApi;
import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLClientApi;
import io.quarkus.test.QuarkusUnitTest;

public class StorkAndGraphQLClientTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addAsResource(new StringAsset(
"quarkus.smallrye-graphql-client.typesafeclient.url=stork://foo-service/graphql\n" +
"quarkus.stork.foo-service.service-discovery.type=static\n" +
"quarkus.stork.foo-service.service-discovery.address-list=${quarkus.http.host:localhost}:${quarkus.http.test-port:8081}"),
"application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Inject
TestingGraphQLClientApi client;

@Test
public void performQuery() {
List<Person> people = client.people();
assertEquals("John", people.get(0).getFirstName());
assertEquals("Arthur", people.get(1).getFirstName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.quarkus.smallrye.graphql.deployment;

import static io.restassured.RestAssured.get;
import static org.hamcrest.Matchers.containsString;

import javax.validation.Valid;
import javax.validation.constraints.Size;

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

/**
* Basic test to verify that bean validation constraints on input fields are transformed into GraphQL directives when
* the option to include directives in the schema is enabled.
*/
public class BeanValidationGraphQLDirectivesTest extends AbstractGraphQLTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(Person.class)
.addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true"),
"application.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Test
public void validateDirectivesPresentInSchema() {
get("/graphql/schema.graphql")
.then()
.body(containsString("input PersonInput {\n" +
" name: String @constraint(maxLength : 20, minLength : 5)\n" +
"}\n"))
.body(containsString(
"queryWithConstrainedArgument(constrained: String @constraint(maxLength : 123)): String"));
}

@GraphQLApi
public static class ValidationApi {

@Query
public String query(@Valid Person person) {
return null;
}

@Query
public String queryWithConstrainedArgument(@Size(max = 123) String constrained) {
return null;
}

}

public static class Person {

@Size(min = 5, max = 20)
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

}