Skip to content

Commit

Permalink
Added MP's Input.class to the index (SmallRye GraphQL Client) + test
Browse files Browse the repository at this point in the history
  • Loading branch information
mskacelik committed Apr 3, 2024
1 parent 64382b5 commit 067643b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;

import org.eclipse.microprofile.graphql.Input;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
Expand Down Expand Up @@ -236,6 +237,7 @@ void setAdditionalClassesToIndex(BuildProducer<AdditionalIndexedClassesBuildItem
if (quarkusConfig.enableBuildTimeScanning) {
additionalClassesToIndex.produce(new AdditionalIndexedClassesBuildItem(Closeable.class.getName()));
additionalClassesToIndex.produce(new AdditionalIndexedClassesBuildItem(AutoCloseable.class.getName()));
additionalClassesToIndex.produce(new AdditionalIndexedClassesBuildItem(Input.class.getName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.quarkus.smallrye.graphql.client.deployment;

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

import jakarta.inject.Inject;

import org.jboss.shrinkwrap.api.asset.EmptyAsset;
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.PersonDto;
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 TypeSafeGraphQLParameterInputNameWithClientModelTest {

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@Inject
TestingGraphQLClientApi client;

@Test
public void performQuery() {
final String expectedName = "Mark";
String actualPerson = client.getNameOfThePerson(new PersonDto(expectedName));
assertEquals(expectedName, actualPerson);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.smallrye.graphql.client.deployment.model;

import org.eclipse.microprofile.graphql.Input;

@Input("PersonInput")
public class PersonDto {
private String name;

public PersonDto() {
}

public PersonDto(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import org.eclipse.microprofile.graphql.Query;

import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
import io.smallrye.graphql.execution.context.SmallRyeContext;

@GraphQLApi
public class TestingGraphQLApi {

@Inject
CurrentVertxRequest request;

@Inject
SmallRyeContext ctx;

@Query
public List<Person> people() {
Person person1 = new Person();
Expand All @@ -36,4 +40,14 @@ public String returnHeader(String key) {
return request.getCurrent().request().getHeader(key);
}

private final String EXPECTED_QUERY_FOR_NAME_OF_THE_PERSON = "query nameOfThePerson($personDto: PersonInput) { nameOfThePerson(personDto: $personDto) }";

@Query
public String getNameOfThePerson(PersonDto personDto) {
if (!ctx.getQuery().equals(EXPECTED_QUERY_FOR_NAME_OF_THE_PERSON))
throw new RuntimeException(
String.format("Wrong Query - expected: %s\n actual: %s", EXPECTED_QUERY_FOR_NAME_OF_THE_PERSON,
ctx.getQuery()));
return personDto.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public interface TestingGraphQLClientApi {
@Query
public String returnHeader(String key);

@Query
public String getNameOfThePerson(PersonDto personDto);

}

0 comments on commit 067643b

Please sign in to comment.