You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/08/23 16:04:33 UTC
(grails-core) branch chore/graphql-root-cleanup created (now cc285e7d6a)
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a change to branch chore/graphql-root-cleanup
in repository https://gitbox.apache.org/repos/asf/grails-core.git
at cc285e7d6a Make Schema.generate()'s null return explicit
This branch includes the following new commits:
new 52d4082f67 Consolidate GraphQLEntityHelper.getMapping's multi-branch reassignment
new 2fc564219e Remove unnecessary public modifier from GraphQLServiceManager.getService
new cc285e7d6a Make Schema.generate()'s null return explicit
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(grails-core) 03/03: Make Schema.generate()'s null return explicit
Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch chore/graphql-root-cleanup
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit cc285e7d6a2bf460250a9ccdcba212ffae64939d
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Aug 23 09:50:48 2026 -0500
Make Schema.generate()'s null return explicit
When no entity contributes any query fields, the method fell off the
end without a return statement instead of explicitly returning null.
Behavior is unchanged (Groovy allows the implicit null under
CompileStatic), but the fall-through was ambiguous to both the reader
and the compiler's control-flow analysis. Already covered by
DisableAllOpSpec, which asserts generate() returns null when every
entity's operations are disabled.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy | 1 +
1 file changed, 1 insertion(+)
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
index 7d583af2ee..50bce08627 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/Schema.groovy
@@ -544,6 +544,7 @@ class Schema {
schema.query(query)
return schema.build()
}
+ null
}
}
(grails-core) 02/03: Remove unnecessary public modifier from GraphQLServiceManager.getService
Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch chore/graphql-root-cleanup
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 2fc564219e66c7a7b83b0641cde4acaddc01de00
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Aug 23 09:46:51 2026 -0500
Remove unnecessary public modifier from GraphQLServiceManager.getService
Groovy methods are public by default; the explicit modifier was
redundant.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../main/groovy/org/grails/gorm/graphql/GraphQLServiceManager.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLServiceManager.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLServiceManager.groovy
index f85b8539d9..3a3c374c03 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLServiceManager.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLServiceManager.groovy
@@ -39,7 +39,7 @@ class GraphQLServiceManager {
services.put(clazz, service)
}
- public <T extends Object> T getService(Class<T> serviceType) throws ServiceNotFoundException {
+ <T extends Object> T getService(Class<T> serviceType) throws ServiceNotFoundException {
if (services.containsKey(serviceType)) {
return (T)services.get(serviceType)
}
(grails-core) 01/03: Consolidate GraphQLEntityHelper.getMapping's multi-branch reassignment
Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch chore/graphql-root-cleanup
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 52d4082f6762baaade94124a428f716b50e5cb17
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sun Aug 23 09:46:48 2026 -0500
Consolidate GraphQLEntityHelper.getMapping's multi-branch reassignment
mapping was declared null then conditionally reassigned across four
if/else-if branches before being read - the same shape flagged
elsewhere in this cleanup as a false "assignment is not used" warning
once IntelliJ's flow analysis loses track of a variable reassigned
across many branches. Extracted the reflection lookup
(findGraphqlProperty), the graphql-value-to-GraphQLMapping conversion
(toGraphQLMapping, with each branch returning directly), and the
overall build/verify sequence (buildMapping) into their own methods,
so getMapping itself is now a single containsKey-check plus a
single build+cache assignment.
Added direct unit coverage for getMapping via a Stub(PersistentEntity)
(no static graphql property, a Boolean true, an unsupported property
type that should throw IllegalMappingException, and cache identity
across repeated calls) - previously it was only exercised indirectly
through getDescription and other specs' Closure-based mappings.
Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
.../grails/gorm/graphql/GraphQLEntityHelper.groovy | 59 +++++++++++++---------
.../gorm/graphql/GraphQLEntityHelperSpec.groovy | 58 +++++++++++++++++++++
2 files changed, 94 insertions(+), 23 deletions(-)
diff --git a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLEntityHelper.groovy b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLEntityHelper.groovy
index a2a2cce9ac..f003af6ed7 100644
--- a/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLEntityHelper.groovy
+++ b/grails-data-graphql/core/src/main/groovy/org/grails/gorm/graphql/GraphQLEntityHelper.groovy
@@ -73,35 +73,48 @@ class GraphQLEntityHelper {
if (mappings.containsKey(entity)) {
return mappings.get(entity)
}
- Object graphql
+ GraphQLMapping mapping = buildMapping(entity)
+ mappings.put(entity, mapping)
+ mapping
+ }
+
+ private static GraphQLMapping buildMapping(PersistentEntity entity) {
+ Object graphql = findGraphqlProperty(entity)
+ if (graphql == null) {
+ return null
+ }
+
+ GraphQLMapping mapping = toGraphQLMapping(graphql)
+ if (!(mapping instanceof GraphQLMapping)) {
+ throw new IllegalMappingException("The static graphql property on ${entity.name} is not a Boolean, Closure, or GraphQLMapping")
+ }
+ verifyMapping(mapping, entity)
+ mapping
+ }
+
+ private static Object findGraphqlProperty(PersistentEntity entity) {
for (Method method: entity.javaClass.declaredMethods) {
if (Modifier.isStatic(method.modifiers) && method.name.equalsIgnoreCase('getgraphql')) {
- graphql = method.invoke(null)
- break
+ return method.invoke(null)
}
}
- GraphQLMapping mapping = null
- if (graphql != null) {
- if (graphql == Boolean.TRUE) {
- mapping = new GraphQLMapping()
- }
- else if (graphql instanceof Closure) {
- mapping = new GraphQLMapping().build((Closure)graphql)
- }
- else if (graphql instanceof LazyGraphQLMapping) {
- mapping = ((LazyGraphQLMapping)graphql).initialize()
- }
- else if (graphql instanceof GraphQLMapping) {
- mapping = (GraphQLMapping)graphql
- }
+ null
+ }
- if (!(mapping instanceof GraphQLMapping)) {
- throw new IllegalMappingException("The static graphql property on ${entity.name} is not a Boolean, Closure, or GraphQLMapping")
- }
- verifyMapping(mapping, entity)
+ private static GraphQLMapping toGraphQLMapping(Object graphql) {
+ if (graphql == Boolean.TRUE) {
+ return new GraphQLMapping()
}
- mappings.put(entity, mapping)
- mapping
+ if (graphql instanceof Closure) {
+ return new GraphQLMapping().build((Closure) graphql)
+ }
+ if (graphql instanceof LazyGraphQLMapping) {
+ return ((LazyGraphQLMapping) graphql).initialize()
+ }
+ if (graphql instanceof GraphQLMapping) {
+ return (GraphQLMapping) graphql
+ }
+ null
}
static void verifyMapping(GraphQLMapping mapping, PersistentEntity entity) {
diff --git a/grails-data-graphql/core/src/test/groovy/org/grails/gorm/graphql/GraphQLEntityHelperSpec.groovy b/grails-data-graphql/core/src/test/groovy/org/grails/gorm/graphql/GraphQLEntityHelperSpec.groovy
index f28f14d1e4..ebff7518e5 100644
--- a/grails-data-graphql/core/src/test/groovy/org/grails/gorm/graphql/GraphQLEntityHelperSpec.groovy
+++ b/grails-data-graphql/core/src/test/groovy/org/grails/gorm/graphql/GraphQLEntityHelperSpec.groovy
@@ -19,10 +19,12 @@
package org.grails.gorm.graphql
+import org.grails.datastore.mapping.model.IllegalMappingException
import org.grails.datastore.mapping.model.PersistentEntity
import org.grails.gorm.graphql.domain.general.description.Annotation
import org.grails.gorm.graphql.domain.hibernate.description.MappingComment
import org.grails.gorm.graphql.domain.general.description.MappingDescription
+import org.grails.gorm.graphql.entity.dsl.GraphQLMapping
/**
* Created by jameskleeh on 7/25/17.
@@ -56,4 +58,60 @@ class GraphQLEntityHelperSpec extends HibernateSpec {
expect:
GraphQLEntityHelper.getDescription(entity) == 'MappingDescription class'
}
+
+ void "test getMapping returns null when no static graphql property is present"() {
+ given:
+ PersistentEntity entity = Stub(PersistentEntity) {
+ getJavaClass() >> NoGraphqlMapping
+ }
+
+ expect:
+ GraphQLEntityHelper.getMapping(entity) == null
+ }
+
+ void "test getMapping builds a default mapping from a Boolean true"() {
+ given:
+ PersistentEntity entity = Stub(PersistentEntity) {
+ getJavaClass() >> BooleanGraphqlMapping
+ }
+
+ expect:
+ GraphQLEntityHelper.getMapping(entity) instanceof GraphQLMapping
+ }
+
+ void "test getMapping throws for an unsupported graphql property type"() {
+ given:
+ PersistentEntity entity = Stub(PersistentEntity) {
+ getJavaClass() >> InvalidGraphqlMapping
+ getName() >> 'InvalidGraphqlMapping'
+ }
+
+ when:
+ GraphQLEntityHelper.getMapping(entity)
+
+ then:
+ IllegalMappingException ex = thrown(IllegalMappingException)
+ ex.message.contains('InvalidGraphqlMapping')
+ }
+
+ void "test getMapping caches the result for repeated calls with the same entity"() {
+ given:
+ PersistentEntity entity = Stub(PersistentEntity) {
+ getJavaClass() >> BooleanGraphqlMapping
+ }
+
+ expect:
+ GraphQLEntityHelper.getMapping(entity).is(GraphQLEntityHelper.getMapping(entity))
+ }
+
+ static class NoGraphqlMapping {
+ }
+
+ static class BooleanGraphqlMapping {
+ static graphql = true
+ }
+
+ static class InvalidGraphqlMapping {
+ static graphql = 42
+ }
}