Skip to content
This repository was archived by the owner on Mar 10, 2025. It is now read-only.
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
84 changes: 40 additions & 44 deletions core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -101,12 +100,12 @@ class Schema {
Map<String, GraphQLInputType> buildListArguments(Map<String, Class> arguments) {
if (arguments != null) {
Map<String, GraphQLInputType> listArguments = [:]
for (Map.Entry<String, Class> entry: arguments) {
for (Map.Entry<String, Class> 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
}
Expand Down Expand Up @@ -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<String, Class> identity: identities) {
GraphQLInputType inputType = (GraphQLInputType)typeManager.getType(identity.value, false)
for (Map.Entry<String, Class> 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))
Expand All @@ -244,8 +240,8 @@ class Schema {

Set<PersistentEntity> 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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<String, GraphQLInputType> argument: listArguments) {
for (Map.Entry<String, GraphQLInputType> argument : listArguments) {
queryAll.argument(
newArgument()
.name(argument.key)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

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

Expand All @@ -478,7 +474,7 @@ class Schema {

Set<GraphQLType> additionalTypes = []

for (PersistentEntity entity: childrenNotMapped) {
for (PersistentEntity entity : childrenNotMapped) {
GraphQLMapping mapping = GraphQLEntityHelper.getMapping(entity.rootEntity)
if (mapping == null) {
continue
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class GraphQLMapping implements Describable<GraphQLMapping>, Deprecatable<GraphQ
*/
@CompileDynamic
Object methodMissing(String name, Object args) {
if (args && args.getClass().isArray()) {
if (args && args.getClass().array) {

if (args[0] instanceof Closure) {
property(name, (Closure) args[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class CustomOperation<T> implements Named<T>, Describable<T>, Deprecata
}
}

if (!arguments.isEmpty()) {
if (!arguments.empty) {
for (CustomArgument argument: arguments) {
customQuery.argument(argument.getArgument(typeManager, mappingContext))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CountEntityDataFetcher extends DefaultGormDataFetcher<Integer> implements

@Override
Integer get(DataFetchingEnvironment environment) {
(Integer)withTransaction(true) {
(Integer) withTransaction(true) {
queryCount()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.grails.gorm.graphql.fetcher.GraphQLDataFetcherType
/**
* A class for creating entities with GraphQL
*
* @param <T> The domain returnType to create
* @param <T> The domain returnType to create
* @author James Kleeh
* @since 1.0.0
*/
Expand All @@ -24,7 +24,7 @@ class CreateEntityDataFetcher<T> extends DefaultGormDataFetcher<T> implements Bi

@Override
T get(DataFetchingEnvironment environment) {
(T)withTransaction(false) {
(T) withTransaction(false) {
GormEntity instance = newInstance
dataBinder.bind(instance, getArgument(environment))
if (!instance.hasErrors()) {
Expand All @@ -35,11 +35,11 @@ class CreateEntityDataFetcher<T> extends DefaultGormDataFetcher<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GraphQLArgument> arguments = prop.getArguments(typeManager, mapping)
if (!arguments.isEmpty()) {
if (!arguments.empty) {
field.arguments(arguments)
}
}
Expand Down Expand Up @@ -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))
}

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