Skip to content

Commit

Permalink
temp2
Browse files Browse the repository at this point in the history
  • Loading branch information
mskacelik committed Aug 26, 2024
1 parent 0c2770f commit 6302927
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Singleton;

public class ClientModelsExtension implements jakarta.enterprise.inject.spi.Extension {
public class ClientModelsExtension implements Extension {

private final ClientModels clientModels;

public ClientModelsExtension() {
this.clientModels = null;
this(null);
}

public ClientModelsExtension(ClientModels clientModels) {
this.clientModels = clientModels;
}
void registerClientModelsBean(@Observes AfterBeanDiscovery abdEvent, BeanManager bm) {
abdEvent.addBean()

void registerClientModelsBean(@Observes AfterBeanDiscovery afterBeanDiscoveryEvent,
BeanManager beanManager) {
afterBeanDiscoveryEvent.addBean()
.types(ClientModels.class)
.qualifiers(new AnnotationLiteral<Default>() {}, new AnnotationLiteral<Any>() {})
.scope(ApplicationScoped.class)
.scope(Singleton.class)
.beanClass(ClientModels.class)
.createWith(creationalContext -> clientModels);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.wildfly.extension.microprofile.graphql.client.deployment;

import io.smallrye.graphql.client.impl.typesafe.cdi.TypesafeGraphQLClientExtension;
import io.smallrye.graphql.client.model.ClientModelBuilder;
import io.smallrye.graphql.client.model.ClientModels;
import io.smallrye.graphql.entry.http.ExecutionServlet;
Expand Down Expand Up @@ -67,16 +68,15 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
return;
}
//
// see whether this deployment contains GraphQL annotations
final org.jboss.as.server.deployment.annotation.CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
// final IndexView index = deploymentUnit.getAttachment(Attachments.ANNOTATION_INDEX);
// final IndexView index = deploymentUnit.getAttachment(Attachments.ANNOTATION_INDEX);
if (compositeIndex.getAnnotations(GRAPHQL_CLIENT_API).isEmpty()) {
return;
}
final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final WeldCapability weldCapability;
// MicroProfileGraphQLClientLogger.LOGGER.activatingGraphQLForDeployment(deploymentUnit.getName());
MicroProfileGraphQLClientLogger.LOGGER.activatingGraphQLForDeployment(deploymentUnit.getName());
Collection<IndexView> indexViews = compositeIndex.getIndexes().stream()
.map(index -> (IndexView) index) // Assuming Index has an asIndexView() method
.collect(Collectors.toList());
Expand All @@ -92,88 +92,8 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
final ClientModels clientModels = ClientModelBuilder.build(org.jboss.jandex.CompositeIndex.create(indexViews));
weldCapability.registerExtensionInstance(new ClientModelsExtension(clientModels), deploymentUnit);
}
// clientModels = ClientModelBuilder.build(org.jboss.jandex.CompositeIndex.create(indexViews));

//
//
//
// steps needed for application initialization
// JBossWebMetaData mergedJBossWebMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY).getMergedJBossWebMetaData();
// registerStartupListener(mergedJBossWebMetaData);
// registerExecutionServlet(mergedJBossWebMetaData);
// registerSchemaServlet(mergedJBossWebMetaData);
//
// // if the GraphQL API contains subscriptions, deploy the relevant web socket endpoint that handles them
// if (!compositeIndex.getAnnotations(ANNOTATION_SUBSCRIPTION).isEmpty()) {
// WebSocketDeploymentInfo webSocketDeploymentInfo = deploymentUnit.getAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO);
// webSocketDeploymentInfo.addEndpoint(WildFlyGraphQLServerWebSocket.class);
// mergedJBossWebMetaData.setEnableWebSockets(true);
// }
//
}
//
// private boolean hasFederationAnnotations(CompositeIndex index) {
// return !index.getAnnotations(ANNOTATION_FEDERATION_EXTENDS).isEmpty() ||
// !index.getAnnotations(ANNOTATION_FEDERATION_EXTERNAL).isEmpty() ||
// !index.getAnnotations(ANNOTATION_FEDERATION_KEY).isEmpty() ||
// !index.getAnnotations(ANNOTATION_FEDERATION_PROVIDES).isEmpty() ||
// !index.getAnnotations(ANNOTATION_FEDERATION_REQUIRES).isEmpty();
// }
//
//
// // register the io.smallrye.graphql.servlet.StartupListener which needs to be called to initialize
// // the application
// private void registerStartupListener(JBossWebMetaData webdata) {
// ListenerMetaData startupListenerMetadata = new ListenerMetaData();
// startupListenerMetadata.setListenerClass("io.smallrye.graphql.entry.http.StartupListener");
// List<ListenerMetaData> containerListeners = webdata.getListeners();
// if (containerListeners == null) {
// List<ListenerMetaData> list = new ArrayList<>();
// list.add(startupListenerMetadata);
// webdata.setListeners(list);
// } else {
// containerListeners.add(startupListenerMetadata);
// }
// }
//
// private void registerExecutionServlet(JBossWebMetaData webdata) {
// JBossServletMetaData servlet = new JBossServletMetaData();
// servlet.setLoadOnStartup("1");
// servlet.setName("SmallRyeGraphQLExecutionServlet");
// servlet.setServletClass(ExecutionServlet.class.getName());
// servlet.setAsyncSupported(false);
//
// if (webdata.getServlets() == null) {
// webdata.setServlets(new JBossServletsMetaData());
// }
// webdata.getServlets().add(servlet);
// ServletMappingMetaData mapping = new ServletMappingMetaData();
// mapping.setServletName("SmallRyeGraphQLExecutionServlet");
// mapping.setUrlPatterns(Collections.singletonList("/graphql")); // TODO make configurable
// List<ServletMappingMetaData> mappings = webdata.getServletMappings();
// if (mappings != null) {
// mappings.add(mapping);
// } else {
// mappings = new ArrayList<>();
// mappings.add(mapping);
// webdata.setServletMappings(mappings);
// }
//
// }
//
// private void registerSchemaServlet(JBossWebMetaData webdata) {
// JBossServletMetaData servlet = new JBossServletMetaData();
// servlet.setLoadOnStartup("2");
// servlet.setName("SmallRyeGraphQLSchemaServlet");
// servlet.setServletClass(SchemaServlet.class.getName());
// servlet.setAsyncSupported(false);
// webdata.getServlets().add(servlet);
// ServletMappingMetaData mapping = new ServletMappingMetaData();
// mapping.setServletName("SmallRyeGraphQLSchemaServlet");
// mapping.setUrlPatterns(Collections.singletonList("/graphql/schema.graphql")); // TODO make configurable
// webdata.getServletMappings().add(mapping);
// }

@Override
public void undeploy(DeploymentUnit deploymentUnit) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@

<resources>
<artifact name="${io.smallrye:smallrye-graphql-client}"/>
<artifact name="${io.smallrye:smallrye-graphql-client-model}"/>
<artifact name="${io.smallrye:smallrye-graphql-client-model-builder}"/>
</resources>

<dependencies>
<module name="io.smallrye.graphql.client.api" export="true"/>
<module name="io.smallrye.graphql.client.api" export="true" services="import"/>
<module name="org.jboss.resteasy.resteasy-jaxrs"/>
<module name="jakarta.ws.rs.api"/>
<module name="org.slf4j"/>
<module name="org.eclipse.microprofile.config.api"/>
<module name="io.smallrye.config"/>
<module name="jakarta.enterprise.api"/>
<module name="jakarta.json.bind.api"/>
<module name="org.jboss.jandex"/>
<module name="javax.sql.api"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
<artifact name="${io.vertx:vertx-web-client}"/>
<artifact name="${io.vertx:vertx-web-common}"/>
<artifact name="${io.vertx:vertx-uri-template}"/>
<artifact name="${io.smallrye:smallrye-graphql-client-model}"/>
<artifact name="${io.smallrye:smallrye-graphql-client-model-builder}"/>
</resources>

<dependencies>
Expand Down
21 changes: 20 additions & 1 deletion quickstart-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<properties>
<maven.deploy.skip>true</maven.deploy.skip>

<compiler-plugin.version>3.13.0</compiler-plugin.version>
<!-- these are only relevant for testing -->
<jboss.dist>${project.basedir}/target/wildfly</jboss.dist>
<jboss.home>${jboss.dist}</jboss.home>
Expand Down Expand Up @@ -121,6 +121,11 @@
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- to deploy the GraphiQL UI, we have to include this dependency in the resulting WAR -->
<dependency>
Expand Down Expand Up @@ -165,6 +170,10 @@
<artifactId>wildfly-arquillian-protocol-jmx</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-api</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -261,6 +270,16 @@
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import java.util.Set;

@ApplicationPath("/")
public class Application extends jakarta.ws.rs.core.Application {
public class Application extends jakarta.ws.rs.core.Application {

@Override
public Set<Class<?>> getClasses() {
return Collections.singleton(Resource.class);
return Collections.singleton(FilmResource.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Film {
private Integer episodeID;
private String director;
private LocalDate releaseDate;
private String desc;

public String getTitle() {
return title;
Expand Down Expand Up @@ -41,4 +42,11 @@ public void setReleaseDate(LocalDate releaseDate) {
this.releaseDate = releaseDate;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package org.wildfly.extras.quickstart.microprofile.graphql.client;

import java.util.List;

import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi;
import org.eclipse.microprofile.graphql.DefaultValue;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.Name;
import org.eclipse.microprofile.graphql.Query;

@GraphQLClientApi
interface FilmClientApi {
@Query
List<Film> allFilms();
List<Film> getAllFilms();

@Query
Film getFilm(@Name("filmId") int id);

// @Mutation
// Hero createHero(Hero hero);
//
// @Mutation
// Hero deleteHero(int id);
//
// @Query
// List<Hero> getHeroesWithSurname(@DefaultValue("Skywalker") String surname);
}
Loading

0 comments on commit 6302927

Please sign in to comment.