diff --git a/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy b/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy index c6b48c8b..1be9008e 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy @@ -21,13 +21,7 @@ import org.grails.gorm.graphql.entity.property.manager.GraphQLDomainPropertyMana import org.grails.gorm.graphql.fetcher.BindingGormDataFetcher import org.grails.gorm.graphql.fetcher.DeletingGormDataFetcher import org.grails.gorm.graphql.fetcher.PaginatingGormDataFetcher -import org.grails.gorm.graphql.fetcher.impl.CountEntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.CreateEntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.DeleteEntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.EntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.PaginatedEntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.SingleEntityDataFetcher -import org.grails.gorm.graphql.fetcher.impl.UpdateEntityDataFetcher +import org.grails.gorm.graphql.fetcher.impl.* import org.grails.gorm.graphql.fetcher.interceptor.InterceptingDataFetcher import org.grails.gorm.graphql.fetcher.interceptor.InterceptorInvoker import org.grails.gorm.graphql.fetcher.interceptor.MutationInterceptorInvoker @@ -51,9 +45,14 @@ import org.grails.gorm.graphql.types.scalars.coercing.DateCoercion import org.grails.gorm.graphql.types.scalars.coercing.jsr310.* import org.grails.gorm.graphql.types.scalars.jsr310.* import org.springframework.context.support.StaticMessageSource - import javax.annotation.PostConstruct -import java.time.* +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.OffsetDateTime +import java.time.OffsetTime +import java.time.ZonedDateTime import static graphql.schema.FieldCoordinates.coordinates import static graphql.schema.GraphQLArgument.newArgument @@ -101,12 +100,12 @@ class Schema { Map buildListArguments(Map arguments) { if (arguments != null) { Map listArguments = [:] - for (Map.Entry entry: arguments) { + for (Map.Entry entry : arguments) { GraphQLType type = typeManager.getType(entry.value) if (!(type instanceof GraphQLInputType)) { throw new IllegalArgumentException("Error while setting list arguments. Invalid returnType found for ${entry.value.name}. GraphQLType found ${type} of returnType ${type.class.name} is not an instance of ${GraphQLInputType.name}") } - listArguments.put(entry.key, (GraphQLInputType)type) + listArguments.put(entry.key, (GraphQLInputType) type) } return listArguments } @@ -202,28 +201,25 @@ class Schema { if (entity.identity != null) { identities.put(entity.identity.name, entity.identity.type) - } - else if (entity.compositeIdentity != null) { - for (PersistentProperty identity: entity.compositeIdentity) { + } else if (entity.compositeIdentity != null) { + for (PersistentProperty identity : entity.compositeIdentity) { if (identity instanceof Association) { - PersistentEntity associatedEntity = ((Association)identity).associatedEntity + PersistentEntity associatedEntity = ((Association) identity).associatedEntity if (associatedEntity.identity != null) { identities.put(identity.name, associatedEntity.identity.type) - } - else { + } else { throw new UnsupportedOperationException("Mapping domain classes with nested composite keys is not currently supported. ${identity.toString()} has a composite key.") } - } - else { + } else { identities.put(identity.name, identity.type) } } } - for (Map.Entry identity: identities) { - GraphQLInputType inputType = (GraphQLInputType)typeManager.getType(identity.value, false) + for (Map.Entry identity : identities) { + GraphQLInputType inputType = (GraphQLInputType) typeManager.getType(identity.value, false) - for (GraphQLFieldDefinition.Builder builder: builders) { + for (GraphQLFieldDefinition.Builder builder : builders) { builder.argument(newArgument() .name(identity.key) .type(inputType)) @@ -244,8 +240,8 @@ class Schema { Set childrenNotMapped = [] - for (MappingContext mappingContext: mappingContexts) { - for (PersistentEntity entity: mappingContext.persistentEntities) { + for (MappingContext mappingContext : mappingContexts) { + for (PersistentEntity entity : mappingContext.persistentEntities) { GraphQLMapping mapping = GraphQLEntityHelper.getMapping(entity) if (mapping == null) { @@ -283,10 +279,10 @@ class Schema { .deprecate(getOperation.deprecationReason) codeRegistry - .dataFetcher( - coordinates(QUERY_TYPE_NAME, GET_FIELD_NAME), - new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, GET, getFetcher) - ) + .dataFetcher( + coordinates(QUERY_TYPE_NAME, GET_FIELD_NAME), + new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, GET, getFetcher) + ) requiresIdentityArguments.add(queryOne) queryFields.add(queryOne) @@ -320,15 +316,15 @@ class Schema { if (listFetcher instanceof PaginatingGormDataFetcher) { ((PaginatingGormDataFetcher) listFetcher).responseHandler = paginationResponseHandler } - + codeRegistry.dataFetcher( coordinates(QUERY_TYPE_NAME, LIST_FIELD_NAME), new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, LIST, listFetcher) ) - + queryFields.add(queryAll) - for (Map.Entry argument: listArguments) { + for (Map.Entry argument : listArguments) { queryAll.argument( newArgument() .name(argument.key) @@ -342,7 +338,7 @@ class Schema { DataFetcher countFetcher = dataFetcherManager.getReadingFetcher(entity, COUNT).orElse(new CountEntityDataFetcher(entity)) final String COUNT_FIELD_NAME = namingConvention.getCount(entity) - final GraphQLOutputType COUNT_OUTPUT_TYPE = (GraphQLOutputType)typeManager.getType(Integer) + final GraphQLOutputType COUNT_OUTPUT_TYPE = (GraphQLOutputType) typeManager.getType(Integer) GraphQLFieldDefinition.Builder queryCount = newFieldDefinition() .name(COUNT_FIELD_NAME) @@ -381,14 +377,14 @@ class Schema { .description(createOperation.description) .deprecate(createOperation.deprecationReason) .argument(newArgument() - .name(entity.decapitalizedName) - .type(createObjectType)) + .name(entity.decapitalizedName) + .type(createObjectType)) codeRegistry.dataFetcher( coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME), new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, CREATE, createFetcher) ) - + mutationFields.add(create) } @@ -443,9 +439,9 @@ class Schema { .deprecate(deleteOperation.deprecationReason) codeRegistry.dataFetcher( - coordinates(MUTATION_TYPE_NAME, DELETE_FIELD_NAME), - new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, DELETE, deleteFetcher) - ) + coordinates(MUTATION_TYPE_NAME, DELETE_FIELD_NAME), + new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, DELETE, deleteFetcher) + ) requiresIdentityArguments.add(delete) mutationFields.add(delete) @@ -454,19 +450,19 @@ class Schema { final GraphQLFieldDefinition.Builder[] BUILDERS = requiresIdentityArguments as GraphQLFieldDefinition.Builder[] populateIdentityArguments(entity, BUILDERS) - for (Closure c: postIdentityExecutables) { + for (Closure c : postIdentityExecutables) { c.call() } - for (CustomOperation operation: mapping.customQueryOperations) { + for (CustomOperation operation : mapping.customQueryOperations) { queryFields.add(operation.createField(entity, serviceManager, mappingContext, listArguments)) } - for (CustomOperation operation: mapping.customMutationOperations) { + for (CustomOperation operation : mapping.customMutationOperations) { mutationFields.add(operation.createField(entity, serviceManager, mappingContext, Collections.emptyMap())) } - for (GraphQLSchemaInterceptor schemaInterceptor: interceptorManager.interceptors) { + for (GraphQLSchemaInterceptor schemaInterceptor : interceptorManager.interceptors) { schemaInterceptor.interceptEntity(entity, queryFields, mutationFields) } @@ -478,7 +474,7 @@ class Schema { Set additionalTypes = [] - for (PersistentEntity entity: childrenNotMapped) { + for (PersistentEntity entity : childrenNotMapped) { GraphQLMapping mapping = GraphQLEntityHelper.getMapping(entity.rootEntity) if (mapping == null) { continue @@ -487,7 +483,7 @@ class Schema { additionalTypes.add(typeManager.getQueryType(entity, GraphQLPropertyType.OUTPUT)) } - for (GraphQLSchemaInterceptor schemaInterceptor: interceptorManager.interceptors) { + for (GraphQLSchemaInterceptor schemaInterceptor : interceptorManager.interceptors) { schemaInterceptor.interceptSchema(queryType, mutationType, additionalTypes) } diff --git a/core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/GraphQLMapping.groovy b/core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/GraphQLMapping.groovy index 05767b22..69f1fc4d 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/GraphQLMapping.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/entity/dsl/GraphQLMapping.groovy @@ -203,7 +203,7 @@ class GraphQLMapping implements Describable, Deprecatable implements Named, Describable, Deprecata } } - if (!arguments.isEmpty()) { + if (!arguments.empty) { for (CustomArgument argument: arguments) { customQuery.argument(argument.getArgument(typeManager, mappingContext)) } diff --git a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CountEntityDataFetcher.groovy b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CountEntityDataFetcher.groovy index 9ae05be1..f85461f9 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CountEntityDataFetcher.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CountEntityDataFetcher.groovy @@ -23,7 +23,7 @@ class CountEntityDataFetcher extends DefaultGormDataFetcher implements @Override Integer get(DataFetchingEnvironment environment) { - (Integer)withTransaction(true) { + (Integer) withTransaction(true) { queryCount() } } diff --git a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CreateEntityDataFetcher.groovy b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CreateEntityDataFetcher.groovy index 5dd85b97..292dadf1 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CreateEntityDataFetcher.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/CreateEntityDataFetcher.groovy @@ -12,7 +12,7 @@ import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType /** * A class for creating entities with GraphQL * - * @param The domain returnType to create + * @param The domain returnType to create * @author James Kleeh * @since 1.0.0 */ @@ -24,7 +24,7 @@ class CreateEntityDataFetcher extends DefaultGormDataFetcher implements Bi @Override T get(DataFetchingEnvironment environment) { - (T)withTransaction(false) { + (T) withTransaction(false) { GormEntity instance = newInstance dataBinder.bind(instance, getArgument(environment)) if (!instance.hasErrors()) { @@ -35,11 +35,11 @@ class CreateEntityDataFetcher extends DefaultGormDataFetcher implements Bi } protected GormEntity getNewInstance() { - (GormEntity)entity.newInstance() + (GormEntity) entity.newInstance() } protected Map getArgument(DataFetchingEnvironment environment) { - (Map)environment.getArgument(entity.decapitalizedName) + (Map) environment.getArgument(entity.decapitalizedName) } @Override diff --git a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/UpdateEntityDataFetcher.groovy b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/UpdateEntityDataFetcher.groovy index 3e832a45..8f0e6577 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/UpdateEntityDataFetcher.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/impl/UpdateEntityDataFetcher.groovy @@ -8,6 +8,7 @@ import org.grails.gorm.graphql.binding.GraphQLDataBinder import org.grails.gorm.graphql.fetcher.BindingGormDataFetcher import org.grails.gorm.graphql.fetcher.DefaultGormDataFetcher import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType + import static org.grails.datastore.mapping.model.config.GormProperties.VERSION /** diff --git a/core/src/main/groovy/org/grails/gorm/graphql/types/DefaultGraphQLTypeManager.groovy b/core/src/main/groovy/org/grails/gorm/graphql/types/DefaultGraphQLTypeManager.groovy index 5639663a..f576c956 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/types/DefaultGraphQLTypeManager.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/types/DefaultGraphQLTypeManager.groovy @@ -114,7 +114,7 @@ class DefaultGraphQLTypeManager implements GraphQLTypeManager { clazz = Array.newInstance(boxPrimitive(clazz.componentType), 0).getClass() } } - else if (clazz.isPrimitive()) { + else if (clazz.primitive) { clazz = boxPrimitive(clazz) } clazz diff --git a/core/src/main/groovy/org/grails/gorm/graphql/types/output/AbstractObjectTypeBuilder.groovy b/core/src/main/groovy/org/grails/gorm/graphql/types/output/AbstractObjectTypeBuilder.groovy index c350b46f..94d3297f 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/types/output/AbstractObjectTypeBuilder.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/types/output/AbstractObjectTypeBuilder.groovy @@ -68,7 +68,7 @@ abstract class AbstractObjectTypeBuilder implements ObjectTypeBuilder { protected GraphQLFieldDefinition.Builder addFieldArgs(GraphQLFieldDefinition.Builder field, GraphQLDomainProperty prop, MappingContext mapping) { if (prop instanceof Arguable) { List arguments = prop.getArguments(typeManager, mapping) - if (!arguments.isEmpty()) { + if (!arguments.empty) { field.arguments(arguments) } } @@ -124,7 +124,7 @@ abstract class AbstractObjectTypeBuilder implements ObjectTypeBuilder { .description(description) .fields(fields) - if (!entity.isRoot()) { + if (!entity.root) { obj.withInterface(typeManager.createReference(entity.rootEntity, GraphQLPropertyType.OUTPUT)) } diff --git a/gradle.properties b/gradle.properties index 5df0651f..d0864e56 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,12 +11,12 @@ gormHibernateVersion=7.0.3.RELEASE gormMongoDbVersion=7.0.0.RELEASE grailsVersion=4.0.2 grailsDocsVersion=3.3.2 -groovyVersion=2.5.6 +groovyVersion=2.5.14 slf4jVersion=1.7.22 spockVersion=1.3-groovy-2.5 micronautVersion=1.0.3 graphqlJavaVersion=14.1 -codenarcVersion=1.2.1 +codenarcVersion=1.6.1 viewGradleVersion=2.0.0 viewsJsonVersion=2.0.0 servletApiVersion=4.0.1