Search in sources :

Example 1 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project quarkus-github-app by quarkiverse.

the class GitHubService method createInstallationGraphQLClient.

private DynamicGraphQLClient createInstallationGraphQLClient(Long installationId) throws IOException, ExecutionException, InterruptedException {
    CachedInstallationToken installationToken = installationTokenCache.get(installationId);
    DynamicGraphQLClient graphQLClient = DynamicGraphQLClientBuilder.newBuilder().url(gitHubAppRuntimeConfig.instanceEndpoint + "/graphql").header(AUTHORIZATION_HEADER, String.format(AUTHORIZATION_HEADER_BEARER, installationToken.getToken())).build();
    // this call is probably - it's not documented - not counted in the rate limit
    graphQLClient.executeSync("query {\n" + "rateLimit {\n" + "    limit\n" + "    cost\n" + "    remaining\n" + "    resetAt\n" + "  }\n" + "}");
    return graphQLClient;
}
Also used : DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)

Example 2 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project smallrye-graphql by smallrye.

the class DynamicClientSSLTest method clientAuthentication_correctKeystore.

/**
 * Server requests client authentication.
 */
@Test
public void clientAuthentication_correctKeystore() throws Exception {
    HttpServer server = tools.runServer("classpath:ssl/server.pkcs12.keystore", "serverkeystorepassword", "classpath:ssl/server.pkcs12.truststore", "servertruststorepassword");
    try {
        System.setProperty("myclient3/mp-graphql/keystore", "classpath:ssl/client.pkcs12.keystore");
        System.setProperty("myclient3/mp-graphql/keystorePassword", "clientkeystorepassword");
        System.setProperty("myclient3/mp-graphql/keystoreType", "PKCS12");
        WebClientOptions options = new WebClientOptions();
        // don't require server auth
        options.setTrustAll(true);
        DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().configKey("myclient3").options(options).url("https://127.0.0.1:" + server.actualPort()).build();
        client.executeAsync("asd").await().atMost(Duration.ofSeconds(1));
        client.close();
    } finally {
        server.close();
    }
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) HttpServer(io.vertx.core.http.HttpServer) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.jupiter.api.Test)

Example 3 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project smallrye-graphql by smallrye.

the class DynamicClientSSLTest method serverAuthentication_correctTruststore.

/**
 * Client requests server authentication.
 */
@Test
public void serverAuthentication_correctTruststore() throws Exception {
    HttpServer server = tools.runServer("classpath:ssl/server.pkcs12.keystore", "serverkeystorepassword", null, null);
    try {
        System.setProperty("myclient1/mp-graphql/truststore", "classpath:ssl/client.pkcs12.truststore");
        System.setProperty("myclient1/mp-graphql/truststorePassword", "clienttruststorepassword");
        System.setProperty("myclient1/mp-graphql/truststoreType", "PKCS12");
        DynamicGraphQLClient client = DynamicGraphQLClientBuilder.newBuilder().configKey("myclient1").url("https://127.0.0.1:" + server.actualPort()).build();
        client.executeAsync("asd").await().atMost(Duration.ofSeconds(1));
        client.close();
    } finally {
        server.close();
    }
}
Also used : HttpServer(io.vertx.core.http.HttpServer) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.jupiter.api.Test)

Example 4 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project smallrye-graphql by smallrye.

the class RecordAsInputToDynamicClientTest method testSimpleRecord.

@Test
public void testSimpleRecord() throws Exception {
    try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
        Response response = client.executeSync("query { simple {a b} }");
        SimpleRecord result = response.getObject(SimpleRecord.class, "simple");
        assertEquals("a", result.a());
        assertEquals("b", result.b());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) VertxDynamicGraphQLClientBuilder(io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder) DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) Test(org.junit.Test)

Example 5 with DynamicGraphQLClient

use of io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient in project quarkus-github-action by quarkiverse.

the class GitHubEvent method getDynamicGraphQLClient.

public DynamicGraphQLClient getDynamicGraphQLClient() {
    if (inputs.getGitHubToken().isEmpty()) {
        throw new IllegalStateException("No GitHub token provided, unable to initialize the GitHub GraphQL client");
    }
    DynamicGraphQLClient localGitHubGraphQLClient = this.gitHubGraphQLClient;
    if (localGitHubGraphQLClient == null) {
        synchronized (this) {
            localGitHubGraphQLClient = this.gitHubGraphQLClient;
            if (localGitHubGraphQLClient == null) {
                try {
                    this.gitHubGraphQLClient = localGitHubGraphQLClient = DynamicGraphQLClientBuilder.newBuilder().url(context.getGithubGraphQLUrl()).header(AUTHORIZATION_HEADER, String.format(AUTHORIZATION_HEADER_BEARER, inputs.getGitHubToken().get())).build();
                    // this call is probably - it's not documented - not counted in the rate limit
                    localGitHubGraphQLClient.executeSync("query {\n" + "rateLimit {\n" + "    limit\n" + "    cost\n" + "    remaining\n" + "    resetAt\n" + "  }\n" + "}");
                } catch (Exception e) {
                    throw new IllegalStateException("Unable to initialize the GitHub GraphQL client, is the token valid?", e);
                }
            }
        }
    }
    return localGitHubGraphQLClient;
}
Also used : DynamicGraphQLClient(io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient) IOException(java.io.IOException)

Aggregations

DynamicGraphQLClient (io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient)13 VertxDynamicGraphQLClientBuilder (io.smallrye.graphql.client.vertx.dynamic.VertxDynamicGraphQLClientBuilder)6 HttpServer (io.vertx.core.http.HttpServer)5 Test (org.junit.jupiter.api.Test)5 Response (io.smallrye.graphql.client.Response)4 Test (org.junit.Test)3 GitHubEvent (io.quarkiverse.githubapp.GitHubEvent)2 EventAnnotation (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventAnnotation)2 EventDispatchingConfiguration (io.quarkiverse.githubapp.deployment.DispatchingConfiguration.EventDispatchingConfiguration)2 ConfigFileReader (io.quarkiverse.githubapp.runtime.ConfigFileReader)2 MultiplexedEvent (io.quarkiverse.githubapp.runtime.MultiplexedEvent)2 ErrorHandlerBridgeFunction (io.quarkiverse.githubapp.runtime.error.ErrorHandlerBridgeFunction)2 GitHubService (io.quarkiverse.githubapp.runtime.github.GitHubService)2 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)2 BytecodeCreator (io.quarkus.gizmo.BytecodeCreator)2 CatchBlockCreator (io.quarkus.gizmo.CatchBlockCreator)2 ClassCreator (io.quarkus.gizmo.ClassCreator)2 FieldCreator (io.quarkus.gizmo.FieldCreator)2 MethodCreator (io.quarkus.gizmo.MethodCreator)2 ResultHandle (io.quarkus.gizmo.ResultHandle)2