refactor(grails-data-graphql): clean up the types package - #16204
Open
borinquenkid wants to merge 3 commits into
Open
refactor(grails-data-graphql): clean up the types package#16204borinquenkid wants to merge 3 commits into
borinquenkid wants to merge 3 commits into
Conversation
parseDate() returned a bare null instead of Optional.empty() when formats was empty, which caused an NPE from parseLiteral()'s .orElse(null) call on the null return value. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…tTypeBuilder - build(entity) declared a blank GraphQLOutputType reassigned across if/else branches then passed to objectTypeCache.put(...) - Groovy's static type checker narrowed its inferred type to an intersection of GraphQLInterfaceType/GraphQLObjectType's common interfaces rather than the declared GraphQLOutputType, so put() no longer type-checked. Rewrote to return the cached value directly and assign objectType via a ternary instead of branch reassignment, the same treatment given to DefaultGormDataFetcher.resolveDatastore() earlier in this cleanup. - Fixed an unrelated latent bug found while touching build(): fields' ArrayList capacity was computed from `properties.size()` one line before `properties` was declared, which under CompileStatic actually resolved to the GroovyObject-inherited `getProperties()` bean-property map (an unrelated count), not the domain property list. Moved the properties declaration first. - buildInterfaceType(entity, name, description, fields) never used its entity parameter; dropped it (no overrides exist, undocumented). - GraphQLInterfaceType.Builder#typeResolver(TypeResolver) is deprecated since 2018-12-03 in favor of registering the resolver on GraphQLCodeRegistry.Builder by interface name, same migration already applied to CustomOperation/Schema's dataFetcher registration earlier in this cleanup. Added AbstractObjectTypeBuilderSpec, the first coverage of build()'s interface-type branch (a root entity with child entities) - the other object type builder specs construct their builder with a null GraphQLTypeManager and can't reach build() at all. Backs it with a minimal Animal/Dog GORM inheritance fixture and verifies the interface type, the child's implements-interface relationship, and that the migrated codeRegistry type resolver is actually registered. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
graphql-java deprecated Coercing's 1-arg serialize(Object)/parseValue(Object)/ parseLiteral(Object) since 2022-08-22 in favor of context/locale-aware overloads: serialize(Object, GraphQLContext, Locale), parseValue(Object, GraphQLContext, Locale), and parseLiteral(Value<?>, CoercedVariables, GraphQLContext, Locale). Every Coercing implementation in this package overrode the old methods. Migrated all of them - ByteArrayCoercion, CharacterArrayCoercion, CurrencyCoercion, DateCoercion, SqlDateCoercion, TimeCoercion, TimeZoneCoercion, TimestampCoercion, URICoercion, URLCoercion, UUIDCoercion, Jsr310Coercion (the base class LocalDate/LocalDateTime/ LocalTime/OffsetDateTime/OffsetTime/ZonedDateTime all extend, so they needed no direct changes), and InstantCoercion - to the new signatures. Fixed three real bugs surfaced while touching these classes: - ByteArrayCoercion#parseLiteral cast a List<Byte>#toArray() result (always an Object[] at runtime) directly to Byte[], which throws ClassCastException whenever called. Used toArray(new Byte[0]) instead. - CharacterArrayCoercion used the deprecated new Character(char) constructor in three places; switched to Character.valueOf(char). - InstantCoercion#parseLiteral declared a blank Object value reassigned across an if/else-if with no else branch, so an unrecognized Value subtype fell through with value never assigned. Rewrote each branch to return directly instead, the same treatment given elsewhere in this cleanup, and dropped the now-redundant outer `instanceof Value` check since IntValue/StringValue already narrow to Value subtypes. Updated every coercion spec (18 files) to call the new signatures. Removed InstantCoercionSpec's "non Value type returns null" test since that scenario is no longer reachable - the method's static parameter type is now Value<?>, and the still-present "unrecognized Value type" test (BooleanValue) covers the equivalent behavior. Verified against SchemaSpec, which exercises these coercions through real GraphQL query execution, not just direct unit calls. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 task
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryCI / Spring Security Tests (Java 25, shard 1) > :grails-test-examples-spring-security-core-misc-functional-test-app-group:integrationTest
🏷️ Commit: b0f3b14 Test FailuresSecuredControllerSpec > test login as watson, watson belongs to detective groups. All detectives have the role ADMIN (:grails-test-examples-spring-security-core-misc-functional-test-app-group:integrationTest in CI / Spring Security Tests (Java 25, shard 1))Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## test/grails-data-graphql-coverage #16204 +/- ##
===========================================================================
+ Coverage 53.4149% 53.4199% +0.0050%
- Complexity 19459 19460 +1
===========================================================================
Files 2081 2081
Lines 98993 98993
Branches 17361 17361
===========================================================================
+ Hits 52877 52882 +5
+ Misses 38566 38562 -4
+ Partials 7550 7549 -1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #16201. Fixes a series of IntelliJ-flagged issues in
org.grails.gorm.graphql.types.*:DateCoercion: fixed an NPE when no date formats are configured.AbstractObjectTypeBuilder: fixed a control-flow issue wherebuild()'s declared-then-reassignedobjectTypelocal confused Groovy's static type checker onobjectTypeCache.put(...); fixed an unrelated latent bug where anArrayListcapacity was computed from a not-yet-declaredpropertiesvariable (which actually resolved to the unrelatedGroovyObject#getProperties()bean map); removed an unused parameter frombuildInterfaceType; and migrated the deprecatedGraphQLInterfaceType.Builder#typeResolvercall to registration viaGraphQLCodeRegistry.Builder. Added the first direct coverage of the interface-type branch (a root entity with child entities), which no other spec reached.Coercingimplementations intypes.scalars.coercing: migrated off the deprecated 1-argserialize/parseValue/parseLiteraloverrides to the context/locale-aware overloads, fixing aClassCastException-in-waiting inByteArrayCoercion#parseLiteral, a deprecatedCharacterconstructor usage inCharacterArrayCoercion, and an unassigned-variable branch inInstantCoercion#parseLiteralalong the way.Test plan
./gradlew :grails-data-graphql-core:test :grails-data-graphql:test :grails-data-graphql-core:codeStyle :grails-data-graphql:codeStylepasses, includingSchemaSpecwhich exercises these coercions through real GraphQL query execution🤖 Generated with Claude Code