Skip to content

Commit

Permalink
Add metadata for graphql-java-extended-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Jan 4, 2023
1 parent 41adcc9 commit 0b2dab5
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"proxy-config.json",
"reflect-config.json",
"resource-config.json"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"interfaces": [
"graphql.validation.interpolation.ResourceBundleMessageInterpolator$BridgeAnnotation"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "graphql.schema.DataFetchingEnvironmentImpl",
"methods": [
{
"name": "getLocale",
"parameterTypes": []
}
],
"condition": {
"typeReachable": "graphql.GraphQL"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"bundles": [
{
"name": "graphql.validation.ValidationMessages"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "19.1",
"module": "com.graphql-java:graphql-java-extended-validation",
"tested-versions": [
"19.1"
]
}
]
13 changes: 12 additions & 1 deletion metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
},
{
"directory": "org.hibernate.validator/hibernate-validator",
"module": "org.hibernate.validator:hibernate-validator"
"module": "org.hibernate.validator:hibernate-validator",
"requires": [
"org.jboss.logging:jboss-logging"
]
},
{
"directory": "org.apache.tomcat.embed/tomcat-embed-core",
Expand Down Expand Up @@ -146,6 +149,14 @@
"directory": "com.graphql-java/graphql-java",
"module": "com.graphql-java:graphql-java"
},
{
"directory": "com.graphql-java/graphql-java-extended-validation",
"module": "com.graphql-java:graphql-java-extended-validation",
"requires": [
"com.graphql-java:graphql-java",
"org.hibernate.validator:hibernate-validator"
]
},
{
"directory": "net.java.dev.jna/jna",
"module": "net.java.dev.jna:jna"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = tck.testedLibraryVersion.get()

dependencies {
implementation "com.graphql-java:graphql-java-extended-validation:$libraryVersion"
implementation "org.jboss.logging:jboss-logging:3.5.0.Final"
implementation "org.hibernate.validator:hibernate-validator:7.0.4.Final"
testImplementation 'org.assertj:assertj-core:3.22.0'
}

graalvmNative {
binaries {
test {
buildArgs.add('--no-fallback')
buildArgs.add('-H:IncludeLocales=fr')
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 19.1
metadata.dir = com.graphql-java/graphql-java-extended-validation/19.1/
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'graphql-java-extended-validation-tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package graphql;

import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.function.Consumer;

import graphql.schema.GraphQLSchema;
import graphql.schema.StaticDataFetcher;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import graphql.validation.rules.OnValidationErrorStrategy;
import graphql.validation.rules.ValidationRules;
import graphql.validation.schemawiring.ValidationSchemaWiring;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Brian Clozel
*/
public class GraphQlValidationTests {


@Test
void validationErrorQuery() throws Exception {
GraphQLSchema graphQLSchema = parseSchema("validation", runtimeWiringBuilder ->
runtimeWiringBuilder.type("Query", builder ->
builder.dataFetcher("hired", new StaticDataFetcher(true))));
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult result = graphQl.execute("{ hired(application: {name: \"p\"}) }");
assertThat(result.getErrors()).isNotEmpty();
assertThat(result.getErrors().get(0).getMessage()).isEqualTo("/hired/application/name size must be between 3 and 100");
}

@Test
void validationErrorQueryInFrench() throws Exception {
GraphQLSchema graphQLSchema = parseSchema("validation", runtimeWiringBuilder ->
runtimeWiringBuilder.type("Query", builder ->
builder.dataFetcher("hired", new StaticDataFetcher(true))));
GraphQL graphQl = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult result = graphQl.execute(ExecutionInput.newExecutionInput("{ hired(application: {name: \"p\"}) }").locale(Locale.FRENCH).build());
assertThat(result.getErrors()).isNotEmpty();
assertThat(result.getErrors().get(0).getMessage()).isEqualTo("/hired/application/name la taille doit etre comprise entre 3 et 100");
}

private GraphQLSchema parseSchema(String schemaFileName, Consumer<RuntimeWiring.Builder> consumer) throws IOException {
try (InputStream inputStream = GraphQlValidationTests.class.getResourceAsStream(schemaFileName + ".graphqls")) {
TypeDefinitionRegistry registry = new SchemaParser().parse(inputStream);
ValidationRules validationRules = ValidationRules.newValidationRules()
.onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)
.build();
ValidationSchemaWiring schemaWiring = new ValidationSchemaWiring(validationRules);
RuntimeWiring.Builder runtimeWiringBuilder = RuntimeWiring.newRuntimeWiring();
runtimeWiringBuilder.directiveWiring(schemaWiring);
consumer.accept(runtimeWiringBuilder);
return new SchemaGenerator().makeExecutableSchema(registry, runtimeWiringBuilder.build());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"bundles": [],
"resources": {
"includes": [
{
"pattern": "\\Qgraphql/validation.graphqls\\E",
"condition": {
"typeReachable": "graphql.GraphQL"
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type Query {
hired (application : Application!) : Boolean
}

directive @Size(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message")
on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION

input Application {
name : String @Size(min : 3, max : 100)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
graphql.validation.Size.message={path} la taille doit etre comprise entre {min} et {max}
11 changes: 11 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@
}
]
},
{
"test-project-path": "com.graphql-java/graphql-java-extended-validation/19.1",
"libraries": [
{
"name": "com.graphql-java:graphql-java-extended-validation",
"versions": [
"19.1"
]
}
]
},
{
"test-project-path": "net.java.dev.jna/jna/5.8.0",
"libraries": [
Expand Down

0 comments on commit 0b2dab5

Please sign in to comment.