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

Updating to v22 #95

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should always have been present. Dont build a new DataFetcher unless there is rules for that field

I am not sure how this got missed

return fieldDefinition;
}
if (! (fieldsContainer instanceof GraphQLObjectType)) {
// only object type fields can have data fetchers
return fieldDefinition;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version of grpahql-java 22 does not allow setting a data fetcher on GraphQLFieldsContainer anymore since that's nonsensical for interfaces

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
Loading