forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#44044 from mskacelik/issue-43903
Changed quarkus.smallrye-graphql.field-visibility config property to be during ConfigPhase.RUN_TIME
- Loading branch information
Showing
5 changed files
with
151 additions
and
6 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...arkus/smallrye/graphql/deployment/fieldvisibility/FieldVisibilityNoIntrospectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.quarkus.smallrye.graphql.deployment.fieldvisibility; | ||
|
||
import static io.restassured.RestAssured.given; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FieldVisibilityNoIntrospectionTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(FieldVisibilityResource.Book.class, FieldVisibilityResource.Customer.class, | ||
FieldVisibilityResource.Purchase.class, FieldVisibilityResource.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | ||
.addAsResource( | ||
new StringAsset("quarkus.smallrye-graphql.schema-include-introspection-types=true\n" + | ||
"quarkus.smallrye-graphql.field-visibility=no-introspection"), | ||
"application.properties")); | ||
|
||
@Test | ||
void testSchemaWithInvisibleFields() { | ||
given() | ||
.when() | ||
.accept(MediaType.APPLICATION_JSON) | ||
.get("/graphql/schema.graphql") | ||
.then() | ||
.statusCode(200) | ||
.and().body(containsStringButNoFields("type __Directive")) | ||
.and().body(containsStringButNoFields("type __EnumValue")) | ||
.and().body(containsStringButNoFields("type __Field")) | ||
.and().body(containsStringButNoFields("type __InputValue")) | ||
.and().body(containsStringButNoFields("type __Schema")) | ||
.and().body(containsStringButNoFields("type __Type")); | ||
} | ||
|
||
private org.hamcrest.Matcher<String> containsStringButNoFields(String s) { | ||
return new org.hamcrest.BaseMatcher<String>() { | ||
@Override | ||
public boolean matches(Object item) { | ||
return ((String) item).contains(s) && !((String) item).contains(s + " {"); | ||
} | ||
|
||
@Override | ||
public void describeTo(org.hamcrest.Description description) { | ||
description.appendText("a string containing ").appendValue(s) | ||
.appendText(" but not containing (without fields) ").appendValue(s); | ||
} | ||
}; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../java/io/quarkus/smallrye/graphql/deployment/fieldvisibility/FieldVisibilityResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.smallrye.graphql.deployment.fieldvisibility; | ||
|
||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Query; | ||
|
||
// It is important to note that some of the fields are invisible in the GraphQL schema, | ||
// this is because they have been explicitly hidden via the | ||
// quarkus.smallrye-graphql.field-visibility property. | ||
|
||
@GraphQLApi | ||
public class FieldVisibilityResource { | ||
|
||
public static class Book { | ||
public String title; // hidden in the schema | ||
public String author; | ||
} | ||
|
||
public static class Customer { | ||
public String name; // hidden in the schema | ||
public String address; | ||
} | ||
|
||
public static class Purchase { | ||
public Book book; | ||
public Customer customer; | ||
public int count; // hidden in the schema | ||
} | ||
|
||
@Query | ||
public Purchase someFirstQuery(Book book, Customer customer, Purchase purchase) { | ||
return purchase; | ||
} | ||
|
||
@Query | ||
public Customer someSecondQuery() { | ||
return null; | ||
} | ||
|
||
@Query | ||
public Book someThirdQuery() { | ||
return null; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...test/java/io/quarkus/smallrye/graphql/deployment/fieldvisibility/FieldVisibilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.smallrye.graphql.deployment.fieldvisibility; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import jakarta.ws.rs.core.MediaType; | ||
|
||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class FieldVisibilityTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(FieldVisibilityResource.Book.class, FieldVisibilityResource.Customer.class, | ||
FieldVisibilityResource.Purchase.class, FieldVisibilityResource.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | ||
.addAsResource( | ||
new StringAsset( | ||
"quarkus.smallrye-graphql.field-visibility=Purchase.count,Customer.name,Book.*\\.title"), | ||
"application.properties")); | ||
|
||
@Test | ||
void testSchemaWithInvisibleFields() { | ||
given() | ||
.when() | ||
.accept(MediaType.APPLICATION_JSON) | ||
.get("/graphql/schema.graphql") | ||
.then() | ||
.statusCode(200) | ||
.and().body(containsString("type Book {\n author: String\n}")) | ||
.and().body(containsString("input BookInput {\n author: String\n}")) | ||
.and().body(containsString("type Customer {\n address: String\n}")) | ||
.and().body(containsString("type Purchase {\n book: Book\n customer: Customer\n}")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters