Skip to content

Commit

Permalink
Merge pull request #95 from graphql-java/update-to-22
Browse files Browse the repository at this point in the history
Updating to v22
  • Loading branch information
dondonz authored Apr 16, 2024
2 parents c22f5ec + 9439062 commit 8f7a581
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ This library provides extended validation of fields and field arguments for [gra
```

```groovy
implementation 'com.graphql-java:graphql-java-extended-validation:21.0'
implementation 'com.graphql-java:graphql-java-extended-validation:22.0'
```

> Note:
>
> use 22.0 or above for graphql-java 22.x and above
>
> use 21.0 or above for graphql-java 21.x and above
>
> use 20.0 for graphql-java 20.x and above
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}

dependencies {
api "com.graphql-java:graphql-java:21.0"
api "com.graphql-java:graphql-java:22.0"
api "com.graphql-java:graphql-java-extended-scalars:21.0"
api "org.hibernate.validator:hibernate-validator:7.0.1.Final"
api "org.glassfish:jakarta.el:4.0.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLFieldsContainer;
import graphql.schema.GraphQLObjectType;
import graphql.schema.idl.SchemaDirectiveWiring;
import graphql.schema.idl.SchemaDirectiveWiringEnvironment;
import graphql.validation.interpolation.MessageInterpolator;
import graphql.validation.rules.OnValidationErrorStrategy;
import graphql.validation.rules.TargetedValidationRules;
import graphql.validation.rules.ValidationRules;

import java.util.Locale;
Expand All @@ -34,15 +36,23 @@ public ValidationSchemaWiring(ValidationRules ruleCandidates) {
public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition> env) {
GraphQLFieldsContainer fieldsContainer = env.getFieldsContainer();
GraphQLFieldDefinition fieldDefinition = env.getFieldDefinition();

TargetedValidationRules rules = ruleCandidates.buildRulesFor(fieldDefinition, fieldsContainer);
if (rules.isEmpty()) {
return fieldDefinition;
}
if (! (fieldsContainer instanceof GraphQLObjectType)) {
// only object type fields can have data fetchers
return fieldDefinition;
}
GraphQLObjectType graphQLObjectType = (GraphQLObjectType) fieldsContainer;
OnValidationErrorStrategy errorStrategy = ruleCandidates.getOnValidationErrorStrategy();
MessageInterpolator messageInterpolator = ruleCandidates.getMessageInterpolator();
Locale locale = ruleCandidates.getLocale();

final DataFetcher<?> currentDF = env.getCodeRegistry().getDataFetcher(fieldsContainer, fieldDefinition);
final DataFetcher<?> currentDF = env.getCodeRegistry().getDataFetcher(graphQLObjectType, fieldDefinition);
final DataFetcher<?> newDF = buildValidatingDataFetcher(errorStrategy, messageInterpolator, currentDF, locale);

env.getCodeRegistry().dataFetcher(fieldsContainer, fieldDefinition, newDF);
env.getCodeRegistry().dataFetcher(graphQLObjectType, fieldDefinition, newDF);

return fieldDefinition;
}
Expand Down

0 comments on commit 8f7a581

Please sign in to comment.