Skip to content

Commit

Permalink
Merge pull request quarkusio#39857 from mskacelik/srgqlc-added-input-…
Browse files Browse the repository at this point in the history
…to-index

SmallRye GraphQL Client: Added MP's Input.class to the index
  • Loading branch information
jmartisk authored Apr 4, 2024
2 parents 83c53d1 + bf31a24 commit 87a15e5
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 11 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
Expand Up @@ -17,6 +17,7 @@
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.test.QuarkusUnitTest;
import io.smallrye.graphql.client.GraphQLClient;
Expand All @@ -32,7 +33,7 @@ public class DynamicGraphQLClientInjectionTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, Person.class, PersonDto.class)
.addAsResource(new StringAsset("people-client/mp-graphql/url=" + url + "\n" +
"people-client/mp-graphql/header/My-Header=My-Value"),
"application.properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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.test.QuarkusUnitTest;
import io.smallrye.graphql.client.GraphQLClient;
Expand All @@ -32,7 +33,7 @@ public class DynamicGraphQLClientInjectionWithQuarkusConfigTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, Person.class, PersonDto.class)
.addAsResource(new StringAsset("quarkus.smallrye-graphql-client.people.url=" + url + "\n" +
"quarkus.smallrye-graphql-client.people.header.My-Header=My-Value"),
"application.properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.test.QuarkusUnitTest;
import io.quarkus.test.common.http.TestHTTPResource;
Expand All @@ -26,7 +27,7 @@ public class DynamicGraphQLClientProgrammaticUsageTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, Person.class, PersonDto.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@TestHTTPResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -21,7 +22,7 @@ public class StorkAndGraphQLClientTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsResource(new StringAsset(
"quarkus.smallrye-graphql-client.typesafeclient.url=stork://foo-service/graphql\n" +
"quarkus.stork.foo-service.service-discovery.type=static\n" +
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
Expand Up @@ -12,6 +12,7 @@
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.TestingGraphQLClientApiWithNoConfigKey;
import io.quarkus.test.QuarkusUnitTest;
Expand All @@ -27,7 +28,8 @@ public class TypesafeGraphQLClientFQNameTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApiWithNoConfigKey.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApiWithNoConfigKey.class, Person.class,
PersonDto.class)
.addAsResource(
new StringAsset(
"quarkus.smallrye-graphql-client.\"io.quarkus.smallrye.graphql." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -24,7 +25,7 @@ public class TypesafeGraphQLClientInjectionTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsResource(new StringAsset("typesafeclient/mp-graphql/url=" + url + "\n" +
"typesafeclient/mp-graphql/header/My-Header=My-Value"),
"application.properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -24,7 +25,7 @@ public class TypesafeGraphQLClientInjectionWithQuarkusConfigTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsResource(new StringAsset("quarkus.smallrye-graphql-client.typesafeclient.url=" + url + "\n" +
"quarkus.smallrye-graphql-client.typesafeclient.header.My-Header=My-Value"),
"application.properties")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand All @@ -21,7 +22,7 @@ public class TypesafeGraphQLClientProgrammaticUsageTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@TestHTTPResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.net.URL;
import java.util.List;

import org.eclipse.microprofile.graphql.Input;
import org.jboss.jandex.Index;
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;
Expand All @@ -26,15 +28,16 @@ public class TypesafeGraphQLClientProgrammaticUsageWithClientModelTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

@TestHTTPResource
URL url;

@Test
public void performQuery() throws IOException {
Index index = Index.of(GraphQLClientApi.class, TestingGraphQLClientApi.class, Person.class);
Index index = Index.of(GraphQLClientApi.class, TestingGraphQLClientApi.class, Person.class, PersonDto.class,
Input.class);
TestingGraphQLClientApi client = ((VertxTypesafeGraphQLClientBuilder) TypesafeGraphQLClientBuilder.newBuilder())
.clientModels(ClientModelBuilder.build(index))
.endpoint(url.toString() + "/graphql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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.TestingGraphQLClientApiWithNoConfigKey;
import io.quarkus.test.QuarkusUnitTest;
Expand All @@ -28,7 +29,8 @@ public class TypesafeGraphQLClientShortcutTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApiWithNoConfigKey.class, Person.class)
.addClasses(TestingGraphQLApi.class, TestingGraphQLClientApiWithNoConfigKey.class, Person.class,
PersonDto.class)
.addAsResource(
new StringAsset(
"quarkus.smallrye-graphql-client.TestingGraphQLClientApiWithNoConfigKey.url=" + url),
Expand Down
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 87a15e5

Please sign in to comment.