From 1005a734666beab41d268fdada6a2b06ee233be0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 15:54:44 +0530 Subject: [PATCH] Update codenarcVersion to v3 (major) (#120) * Update codenarcVersion to v3 * Remove deprecated `UnnecessarySubstring` rule https://github.com/CodeNarc/CodeNarc/issues/656 * Fix variable names * Remove unnecessary `toString` invocation Calling toString() on [identity] in class org.grails.gorm.graphql.Schema is unnecessary --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Guillermo Calvo --- core/config/codenarc/rules.groovy | 1 - .../org/grails/gorm/graphql/Schema.groovy | 68 +++++++++---------- .../CustomInterceptorInvoker.groovy | 6 +- .../ProvidedInterceptorInvoker.groovy | 4 +- .../types/DefaultGraphQLTypeManager.groovy | 6 +- .../AbstractInputObjectTypeBuilder.groovy | 4 +- .../output/AbstractObjectTypeBuilder.groovy | 16 ++--- gradle.properties | 2 +- 8 files changed, 53 insertions(+), 54 deletions(-) diff --git a/core/config/codenarc/rules.groovy b/core/config/codenarc/rules.groovy index ea763669..6afd8400 100644 --- a/core/config/codenarc/rules.groovy +++ b/core/config/codenarc/rules.groovy @@ -359,7 +359,6 @@ ruleset { UnnecessarySelfAssignment UnnecessarySemicolon UnnecessaryStringInstantiation - UnnecessarySubstring UnnecessaryTernaryExpression UnnecessaryToString UnnecessaryTransientModifier 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 9bd8dcd4..ac64aa6c 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy @@ -214,7 +214,7 @@ class Schema { if (associatedEntity.identity != null) { identities.put(identity.name, associatedEntity.identity.type) } else { - throw new UnsupportedOperationException("Mapping domain classes with nested composite keys is not currently supported. ${identity.toString()} has a composite key.") + throw new UnsupportedOperationException("Mapping domain classes with nested composite keys is not currently supported. ${identity} has a composite key.") } } else { identities.put(identity.name, identity.type) @@ -238,11 +238,11 @@ class Schema { if (!initialized) { initialize() } - final String QUERY_TYPE_NAME = 'Query' - final String MUTATION_TYPE_NAME = 'Mutation' + final String queryTypeName = 'Query' + final String mutationTypeName = 'Mutation' - GraphQLObjectType.Builder queryType = newObject().name(QUERY_TYPE_NAME) - GraphQLObjectType.Builder mutationType = newObject().name(MUTATION_TYPE_NAME) + GraphQLObjectType.Builder queryType = newObject().name(queryTypeName) + GraphQLObjectType.Builder mutationType = newObject().name(mutationTypeName) Set childrenNotMapped = [] @@ -262,7 +262,7 @@ class Schema { List queryFields = [] List mutationFields = [] - final GraphQLOutputType OBJECT_TYPE = typeManager.getQueryType(entity, GraphQLPropertyType.OUTPUT) + final GraphQLOutputType objectType = typeManager.getQueryType(entity, GraphQLPropertyType.OUTPUT) List requiresIdentityArguments = [] List postIdentityExecutables = [] @@ -276,17 +276,17 @@ class Schema { DataFetcher getFetcher = dataFetcherManager.getReadingFetcher(entity, GET).orElse(new SingleEntityDataFetcher(entity)) - final String GET_FIELD_NAME = namingConvention.getGet(entity) + final String getFieldName = namingConvention.getGet(entity) GraphQLFieldDefinition.Builder queryOne = newFieldDefinition() - .name(GET_FIELD_NAME) - .type(OBJECT_TYPE) + .name(getFieldName) + .type(objectType) .description(getOperation.description) .deprecate(getOperation.deprecationReason) codeRegistry .dataFetcher( - coordinates(QUERY_TYPE_NAME, GET_FIELD_NAME), + coordinates(queryTypeName, getFieldName), new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, GET, getFetcher) ) @@ -299,9 +299,9 @@ class Schema { DataFetcher listFetcher = dataFetcherManager.getReadingFetcher(entity, LIST).orElse(null) - final String LIST_FIELD_NAME = namingConvention.getList(entity) + final String listFieldName = namingConvention.getList(entity) GraphQLFieldDefinition.Builder queryAll = newFieldDefinition() - .name(LIST_FIELD_NAME) + .name(listFieldName) .description(listOperation.description) .deprecate(listOperation.deprecationReason) @@ -315,7 +315,7 @@ class Schema { if (listFetcher == null) { listFetcher = new EntityDataFetcher(entity) } - listOutputType = list(OBJECT_TYPE) + listOutputType = list(objectType) } queryAll.type(listOutputType) @@ -324,7 +324,7 @@ class Schema { } codeRegistry.dataFetcher( - coordinates(QUERY_TYPE_NAME, LIST_FIELD_NAME), + coordinates(queryTypeName, listFieldName), new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, LIST, listFetcher) ) @@ -343,17 +343,17 @@ 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 String countFieldName = namingConvention.getCount(entity) + final GraphQLOutputType countOutputType = (GraphQLOutputType) typeManager.getType(Integer) GraphQLFieldDefinition.Builder queryCount = newFieldDefinition() - .name(COUNT_FIELD_NAME) - .type(COUNT_OUTPUT_TYPE) + .name(countFieldName) + .type(countOutputType) .description(countOperation.description) .deprecate(countOperation.deprecationReason) codeRegistry.dataFetcher( - coordinates(QUERY_TYPE_NAME, COUNT_FIELD_NAME), + coordinates(queryTypeName, countFieldName), new InterceptingDataFetcher(entity, serviceManager, queryInterceptorInvoker, COUNT, countFetcher) ) @@ -375,11 +375,11 @@ class Schema { BindingGormDataFetcher createFetcher = dataFetcherManager.getBindingFetcher(entity, CREATE).orElse(new CreateEntityDataFetcher(entity)) createFetcher.dataBinder = dataBinder - final String CREATE_FIELD_NAME = namingConvention.getCreate(entity) + final String createFieldName = namingConvention.getCreate(entity) GraphQLFieldDefinition.Builder create = newFieldDefinition() - .name(CREATE_FIELD_NAME) - .type(OBJECT_TYPE) + .name(createFieldName) + .type(objectType) .description(createOperation.description) .deprecate(createOperation.deprecationReason) .argument(newArgument() @@ -387,7 +387,7 @@ class Schema { .type(createObjectType)) codeRegistry.dataFetcher( - coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME), + coordinates(mutationTypeName, createFieldName), new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, CREATE, createFetcher) ) @@ -406,16 +406,16 @@ class Schema { updateFetcher.dataBinder = dataBinder - final String UPDATE_FIELD_NAME = namingConvention.getUpdate(entity) + final String updateFieldName = namingConvention.getUpdate(entity) GraphQLFieldDefinition.Builder update = newFieldDefinition() - .name(UPDATE_FIELD_NAME) - .type(OBJECT_TYPE) + .name(updateFieldName) + .type(objectType) .description(updateOperation.description) .deprecate(updateOperation.deprecationReason) codeRegistry.dataFetcher( - coordinates(MUTATION_TYPE_NAME, UPDATE_FIELD_NAME), + coordinates(mutationTypeName, updateFieldName), new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, UPDATE, updateFetcher) ) @@ -436,17 +436,17 @@ class Schema { deleteFetcher.responseHandler = deleteResponseHandler - final String DELETE_FIELD_NAME = namingConvention.getDelete(entity) - final GraphQLObjectType DELETE_OBJECT_TYPE = deleteResponseHandler.getObjectType(typeManager) + final String deleteFieldName = namingConvention.getDelete(entity) + final GraphQLObjectType deleteObjectType = deleteResponseHandler.getObjectType(typeManager) GraphQLFieldDefinition.Builder delete = newFieldDefinition() - .name(DELETE_FIELD_NAME) - .type(DELETE_OBJECT_TYPE) + .name(deleteFieldName) + .type(deleteObjectType) .description(deleteOperation.description) .deprecate(deleteOperation.deprecationReason) codeRegistry.dataFetcher( - coordinates(MUTATION_TYPE_NAME, DELETE_FIELD_NAME), + coordinates(mutationTypeName, deleteFieldName), new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, DELETE, deleteFetcher) ) @@ -454,8 +454,8 @@ class Schema { mutationFields.add(delete) } - final GraphQLFieldDefinition.Builder[] BUILDERS = requiresIdentityArguments as GraphQLFieldDefinition.Builder[] - populateIdentityArguments(entity, BUILDERS) + final GraphQLFieldDefinition.Builder[] builders = requiresIdentityArguments as GraphQLFieldDefinition.Builder[] + populateIdentityArguments(entity, builders) for (Closure c : postIdentityExecutables) { c.call() diff --git a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy index c2d4cb88..2de47a6e 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/CustomInterceptorInvoker.groovy @@ -18,10 +18,10 @@ abstract class CustomInterceptorInvoker extends InterceptorInvoker { @Override final boolean invoke(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type) { - final String NAME = getName(environment) - boolean result = invoke(interceptor, NAME, environment) + final String name = getName(environment) + boolean result = invoke(interceptor, name, environment) if (!result) { - log.info("Execution of ${NAME} was prevented by an interceptor") + log.info("Execution of ${name} was prevented by an interceptor") } result } diff --git a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy index 0e6dd41a..c24e511f 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/fetcher/interceptor/ProvidedInterceptorInvoker.groovy @@ -18,10 +18,10 @@ abstract class ProvidedInterceptorInvoker extends InterceptorInvoker { @Override final boolean invoke(GraphQLFetcherInterceptor interceptor, DataFetchingEnvironment environment, GraphQLDataFetcherType type) { - final String NAME = getName(environment) + final String name = getName(environment) boolean result = call(interceptor, environment, type) if (!result) { - log.info("Execution of ${NAME} was prevented by an interceptor") + log.info("Execution of ${name} was prevented by an interceptor") } result } 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 d741b1a8..bf8d49cc 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 @@ -169,12 +169,12 @@ class DefaultGraphQLTypeManager implements GraphQLTypeManager { } for (Enum anEnum: clazz.enumConstants) { - final String NAME = anEnum.name() + final String name = anEnum.name() String description = null String deprecationReason = null - GraphQL valueAnnotation = clazz.getField(NAME).getAnnotation(GraphQL) + GraphQL valueAnnotation = clazz.getField(name).getAnnotation(GraphQL) if (valueAnnotation != null) { if (!valueAnnotation.deprecationReason().empty) { deprecationReason = valueAnnotation.deprecationReason() @@ -187,7 +187,7 @@ class DefaultGraphQLTypeManager implements GraphQLTypeManager { } } - builder.value(NAME, anEnum, description, deprecationReason) + builder.value(name, anEnum, description, deprecationReason) } enumType = builder.build() diff --git a/core/src/main/groovy/org/grails/gorm/graphql/types/input/AbstractInputObjectTypeBuilder.groovy b/core/src/main/groovy/org/grails/gorm/graphql/types/input/AbstractInputObjectTypeBuilder.groovy index d56ef428..02dfef3d 100644 --- a/core/src/main/groovy/org/grails/gorm/graphql/types/input/AbstractInputObjectTypeBuilder.groovy +++ b/core/src/main/groovy/org/grails/gorm/graphql/types/input/AbstractInputObjectTypeBuilder.groovy @@ -51,13 +51,13 @@ abstract class AbstractInputObjectTypeBuilder implements InputObjectTypeBuilder objectTypeCache.get(entity) } else { - final String DESCRIPTION = GraphQLEntityHelper.getDescription(entity) + final String description = GraphQLEntityHelper.getDescription(entity) List properties = builder.getProperties(entity) GraphQLInputObjectType.Builder inputObj = newInputObject() .name(typeManager.namingConvention.getType(entity, type)) - .description(DESCRIPTION) + .description(description) for (GraphQLDomainProperty prop: properties) { if (prop.input) { 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 94d3297f..ecd1b474 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 @@ -84,32 +84,32 @@ abstract class AbstractObjectTypeBuilder implements ObjectTypeBuilder { objectTypeCache.get(entity) } else { - final String DESCRIPTION = GraphQLEntityHelper.getDescription(entity) - final String NAME = typeManager.namingConvention.getType(entity, type) + final String description = GraphQLEntityHelper.getDescription(entity) + final String name = typeManager.namingConvention.getType(entity, type) List fields = new ArrayList<>(properties.size() + 1) List properties = builder.getProperties(entity) for (GraphQLDomainProperty prop: properties) { if (prop.output) { - GraphQLFieldDefinition.Builder field = buildField(prop, NAME) + GraphQLFieldDefinition.Builder field = buildField(prop, name) addFieldArgs(field, prop, entity.mappingContext) fields.add(field.build()) } } if (errorsResponseHandler != null) { - GraphQLFieldDefinition fieldDefinition = errorsResponseHandler.getFieldDefinition(typeManager, NAME) + GraphQLFieldDefinition fieldDefinition = errorsResponseHandler.getFieldDefinition(typeManager, name) fields.add(fieldDefinition) } boolean hasChildEntities = entity.root && !entity.mappingContext.getDirectChildEntities(entity).empty if (hasChildEntities && !type.embedded) { - objectType = buildInterfaceType(entity, NAME, DESCRIPTION, fields) + objectType = buildInterfaceType(entity, name, description, fields) } else { - objectType = buildObjectType(entity, NAME, DESCRIPTION, fields) + objectType = buildObjectType(entity, name, description, fields) } objectTypeCache.put(entity, objectType) @@ -140,8 +140,8 @@ abstract class AbstractObjectTypeBuilder implements ObjectTypeBuilder { .typeResolver(new TypeResolver() { @Override GraphQLObjectType getType(TypeResolutionEnvironment env) { - final String TYPE_NAME = typeManager.namingConvention.getType(env.object.class.simpleName, GraphQLPropertyType.OUTPUT) - (GraphQLObjectType)env.schema.getType(TYPE_NAME) + final String typeName = typeManager.namingConvention.getType(env.object.class.simpleName, GraphQLPropertyType.OUTPUT) + (GraphQLObjectType)env.schema.getType(typeName) } }) diff --git a/gradle.properties b/gradle.properties index a28d298f..32f0ff3d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ spockVersion=2.1-groovy-3.0 micronautVersion=3.10.3 graphqlJavaVersion=20.7 graphqlJavaScalarExtVersion=20.2 -codenarcVersion=1.6.1 +codenarcVersion=3.3.0 viewGradleVersion=2.3.2 viewsJsonVersion=2.3.2 servletApiVersion=4.0.1