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

fix #1689: properly add/remove federation directives #1690

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SmallRye GraphQL
release:
current-version: 2.0.0
next-version: 2.0.1-SNAPSHOT
current-version: 2.0.1
next-version: 2.0.2-SNAPSHOT
20 changes: 4 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
with:
java-version: ${{matrix.java}}
distribution: 'temurin'
cache: 'maven'

- name: Install graphviz
run: sudo apt install graphviz
Expand All @@ -58,19 +59,12 @@ jobs:
ref: main
path: wildfly-graphql-feature-pack

- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- uses: actions/[email protected]
name: set up jdk ${{matrix.java}}
with:
java-version: ${{matrix.java}}
distribution: 'temurin'
cache: 'maven'

- name: build with maven
run: mvn -B install -DskipTests --file pom.xml
Expand Down Expand Up @@ -104,19 +98,12 @@ jobs:
ref: jakarta-rewrite
path: quarkus

- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-

- uses: actions/[email protected]
name: set up jdk ${{matrix.java}}
with:
java-version: ${{matrix.java}}
distribution: 'temurin'
cache: 'maven'

- name: build with maven
run: mvn -B install -DskipTests --file smallrye-graphql/pom.xml
Expand Down Expand Up @@ -145,6 +132,7 @@ jobs:
with:
java-version: 11
distribution: 'temurin'
cache: 'maven'

- name: sonar
env:
Expand Down
2 changes: 1 addition & 1 deletion client/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/generator-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-generator-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-generator</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/implementation-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-implementation-vertx</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

public class DynamicClientSSLTest {

public static final Duration TIMEOUT = Duration.ofSeconds(20);
private SSLTestingTools tools = new SSLTestingTools();

/**
Expand All @@ -25,12 +26,12 @@ public void serverAuthentication_correctTruststore() throws Exception {
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()
try (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();
.build()) {
client.executeAsync("asd").await().atMost(TIMEOUT);
}
} finally {
server.close();
}
Expand All @@ -47,21 +48,15 @@ public void serverAuthentication_badKeystoreOnServer() throws Exception {
System.setProperty("myclient2/mp-graphql/truststore", "classpath:ssl/client.pkcs12.truststore");
System.setProperty("myclient2/mp-graphql/truststorePassword", "clienttruststorepassword");
System.setProperty("myclient2/mp-graphql/truststoreType", "PKCS12");
DynamicGraphQLClient client = null;
try {
client = DynamicGraphQLClientBuilder.newBuilder()
.configKey("myclient2")
.url("https://127.0.0.1:" + server.actualPort())
.build();
client.executeAsync("asd").await().atMost(Duration.ofSeconds(1));
try (DynamicGraphQLClient client = DynamicGraphQLClientBuilder.newBuilder()
.configKey("myclient2")
.url("https://127.0.0.1:" + server.actualPort())
.build()) {
client.executeAsync("asd").await().atMost(TIMEOUT);
Assertions.fail("Connection to server should fail");
} catch (Exception e) {
// verify that the client rejected the server's certificate
assertHasCauseContainingMessage(e, "unable to find valid certification path to requested target");
} finally {
if (client != null) {
client.close();
}
}
} finally {
server.close();
Expand All @@ -81,13 +76,13 @@ public void clientAuthentication_correctKeystore() throws Exception {
System.setProperty("myclient3/mp-graphql/keystoreType", "PKCS12");
WebClientOptions options = new WebClientOptions();
options.setTrustAll(true); // don't require server auth
DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder()
try (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();
.build()) {
client.executeAsync("asd").await().atMost(TIMEOUT);
}
} finally {
server.close();
}
Expand All @@ -106,22 +101,16 @@ public void clientAuthentication_badKeystore() throws Exception {
System.setProperty("myclient4/mp-graphql/keystoreType", "PKCS12");
WebClientOptions options = new WebClientOptions();
options.setTrustAll(true); // don't require server auth
DynamicGraphQLClient client = null;
try {
client = new VertxDynamicGraphQLClientBuilder()
.configKey("myclient4")
.options(options)
.url("https://127.0.0.1:" + server.actualPort())
.build();
client.executeAsync("asd").await().atMost(Duration.ofSeconds(1));
try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder()
.configKey("myclient4")
.options(options)
.url("https://127.0.0.1:" + server.actualPort())
.build()) {
client.executeAsync("asd").await().atMost(TIMEOUT);
Assertions.fail("Connection to server should fail");
} catch (Exception e) {
// verify that the server rejected the client's certificate
assertHasCauseContainingMessage(e, "Received fatal alert: bad_certificate");
} finally {
if (client != null) {
client.close();
}
}
} finally {
server.close();
Expand Down
2 changes: 1 addition & 1 deletion client/implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Array;
import java.time.LocalDate;
import java.util.UUID;

import io.smallrye.graphql.client.core.exceptions.BuildException;
import io.smallrye.graphql.client.impl.core.EnumImpl;
Expand All @@ -10,6 +11,18 @@

public class ValueFormatter {

private final static Class<?>[] QUOTED_VALUES = new Class[] { String.class, Character.class, LocalDate.class, UUID.class };
private final static Class<?>[] UNQUOTED_VALUES = new Class[] { Number.class, Boolean.class };

public static boolean assignableFrom(Class<?> clazz, Class<?>[] candidates) {
for (Class<?> candidate : candidates) {
if (candidate.isAssignableFrom(clazz)) {
return true;
}
}
return false;
}

public static String format(Object value) throws BuildException {
if (value == null) {
return "null";
Expand All @@ -24,17 +37,36 @@ public static String format(Object value) throws BuildException {
return gqlEnum.build();
} else if (value.getClass().isArray()) {
return _processArray(value);
} else if (value instanceof String) {
return _getAsQuotedString(String.valueOf(value));
} else if (value instanceof Character) {
return _getAsQuotedString(String.valueOf(value));
} else if (value instanceof LocalDate) {
return _getAsQuotedString(String.valueOf(value));
} else if (value instanceof Iterable) {
return _processIterable((Iterable<?>) value);
} else {
return value.toString();
if (assignableFrom(value.getClass(), QUOTED_VALUES)) {
return _getAsQuotedString(String.valueOf(value));
} else if (assignableFrom(value.getClass(), UNQUOTED_VALUES)) {
return value.toString();
}
throw new IllegalStateException("Could not format " + value.getClass() + ": Unsupported type.");
}
}

private static String _processIterable(Iterable<?> iterable) throws BuildException {
StringBuilder builder = new StringBuilder();

boolean first = true;
builder.append("[");
for (Object v : iterable) {
if (first) {
first = false;
} else {
builder.append(",");
}
builder.append(format(v));
}
builder.append("]");

return builder.toString();
}

private static String _processArray(Object array) throws BuildException {
StringBuilder builder = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.smallrye.graphql.client.impl.core.utils;

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

import java.util.Date;
import java.util.Map;

import org.junit.jupiter.api.Test;

class ValueFormatterTest {

@Test
public void testUnsupportedInput() {

assertThrows(IllegalStateException.class, () -> {
ValueFormatter.format(new Object());
});

assertThrows(IllegalStateException.class, () -> {
ValueFormatter.format(Map.of("test", "value"));
});

assertThrows(IllegalStateException.class, () -> {
ValueFormatter.format(new Date());
});
}

}
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-parent</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-parent</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>smallrye-graphql-client-tck</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.util.UUID;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -61,7 +62,11 @@ public void arraysTest() throws IOException, URISyntaxException {
prop("charPrimitiveArray", new char[] { 'f', 'o', 'o' }),
prop("charObjectArray", new Character[] { 'f', 'o', 'o' }),

prop("stringArray", new String[] { "foo", "bar", "baz" })))),
prop("stringArray", new String[] { "foo", "bar", "baz" }),

prop("uuidArray",
new UUID[] { UUID.fromString("fc4bb4f4-13fe-4908-8d6a-afa64f1b56c9"),
UUID.fromString("863c9e3c-7538-41b9-9d63-0852f6a50815") })))),
field("boolPrimitiveArray"),
field("boolObjectArray"),

Expand Down Expand Up @@ -89,7 +94,9 @@ public void arraysTest() throws IOException, URISyntaxException {
field("charPrimitiveArray"),
field("charObjectArray"),

field("stringArray"))));
field("stringArray"),

field("uuidArray"))));

String generatedRequest = document.build();
AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
Expand Down
Loading