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

Update codenarcVersion to v3 (major) #120

Merged
merged 4 commits into from
Dec 4, 2023
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
1 change: 0 additions & 1 deletion core/config/codenarc/rules.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ ruleset {
UnnecessarySelfAssignment
UnnecessarySemicolon
UnnecessaryStringInstantiation
UnnecessarySubstring
UnnecessaryTernaryExpression
UnnecessaryToString
UnnecessaryTransientModifier
Expand Down
68 changes: 34 additions & 34 deletions core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<PersistentEntity> childrenNotMapped = []

Expand All @@ -262,7 +262,7 @@ class Schema {
List<GraphQLFieldDefinition.Builder> queryFields = []
List<GraphQLFieldDefinition.Builder> mutationFields = []

final GraphQLOutputType OBJECT_TYPE = typeManager.getQueryType(entity, GraphQLPropertyType.OUTPUT)
final GraphQLOutputType objectType = typeManager.getQueryType(entity, GraphQLPropertyType.OUTPUT)

List<GraphQLFieldDefinition.Builder> requiresIdentityArguments = []
List<Closure> postIdentityExecutables = []
Expand All @@ -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)
)

Expand All @@ -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)

Expand All @@ -315,7 +315,7 @@ class Schema {
if (listFetcher == null) {
listFetcher = new EntityDataFetcher(entity)
}
listOutputType = list(OBJECT_TYPE)
listOutputType = list(objectType)
}
queryAll.type(listOutputType)

Expand All @@ -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)
)

Expand All @@ -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)
)

Expand All @@ -375,19 +375,19 @@ 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()
.name(entity.decapitalizedName)
.type(createObjectType))

codeRegistry.dataFetcher(
coordinates(MUTATION_TYPE_NAME, CREATE_FIELD_NAME),
coordinates(mutationTypeName, createFieldName),
new InterceptingDataFetcher(entity, serviceManager, mutationInterceptorInvoker, CREATE, createFetcher)
)

Expand All @@ -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)
)

Expand All @@ -436,26 +436,26 @@ 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)
)

requiresIdentityArguments.add(delete)
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -187,7 +187,7 @@ class DefaultGraphQLTypeManager implements GraphQLTypeManager {
}
}

builder.value(NAME, anEnum, description, deprecationReason)
builder.value(name, anEnum, description, deprecationReason)
}

enumType = builder.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphQLDomainProperty> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphQLFieldDefinition> fields = new ArrayList<>(properties.size() + 1)

List<GraphQLDomainProperty> 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)
Expand Down Expand Up @@ -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)
}
})

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down