Skip to content

refactor(grails-data-graphql): clean up the fetcher package - #16203

Merged
jdaugherty merged 6 commits into
8.1.xfrom
refactor/graphql-fetcher
Sep 30, 2026
Merged

jdaugherty merged 6 commits into
8.1.xfrom
refactor/graphql-fetcher

Conversation

@borinquenkid

@borinquenkid borinquenkid commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Follows #16201 (merged). Rebased onto 8.1.x. Fixes a series of IntelliJ-flagged issues in org.grails.gorm.graphql.fetcher.*:

  • DeleteEntityDataFetcher/EntityDataFetcher: simplified branch-per-response construction and added a missing (T) cast on executeQuery's DetachedCriteria#list result, matching the cast convention every sibling fetcher already uses.
  • CustomInterceptorInvoker/ProvidedInterceptorInvoker: deduplicated an identical 9-line "resolve name → invoke → log if prevented → return" fragment into a shared logIfPrevented method on InterceptorInvoker.
  • InterceptorInvoker: replaced deprecated DataFetchingEnvironment#getFields() with getMergedField().
  • DefaultGormDataFetcher: fixed a type mismatch (Map<String, Association> → Map<String, Association<?>>... with a documented reason it can't be fully parameterized under Groovy's static type checker), dropped an unused constructor parameter, and extracted resolveDatastore() to eliminate an ambiguous "might not be assigned" local variable.

Test plan

  • ./gradlew :grails-data-graphql-core:test :grails-data-graphql:test :grails-data-graphql-core:codeStyle :grails-data-graphql:codeStyle passes

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 23, 2026 16:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.2479%. Comparing base (95021df) to head (b048d0a).
⚠️ Report is 59 commits behind head on 8.1.x.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##                8.1.x     #16203         +/-   ##
===================================================
+ Coverage     32.7869%   59.2479%   +26.4610%     
- Complexity        563      25135      +24572     
===================================================
  Files              84       2215       +2131     
  Lines            4941     108863     +103922     
  Branches          864      19798      +18934     
===================================================
+ Hits             1620      64499      +62879     
- Misses           3061      35430      +32369     
- Partials          260       8934       +8674     

see 2131 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

This comment has been minimized.

@jdaugherty
jdaugherty force-pushed the test/grails-data-graphql-coverage branch from 36b7716 to df7efef Compare September 23, 2026 21:15
Base automatically changed from test/grails-data-graphql-coverage to 8.0.x September 23, 2026 21:16
@jdaugherty
jdaugherty changed the base branch from 8.0.x to 8.1.x September 30, 2026 14:30
@jdaugherty
jdaugherty force-pushed the refactor/graphql-fetcher branch from 2865d10 to beb5efa Compare September 30, 2026 14:34
borinquenkid and others added 6 commits September 30, 2026 10:46
…tcher

buildCriteria(environment).list(queryArgs) returns a raw List, which
was returned directly from a method declared to return T. Compiles
under CompileStatic only because T is unbounded (erases to Object),
but the assignment isn't actually type-checked - the same shape
PaginatedEntityDataFetcher and every other DefaultGormDataFetcher
subclass already guards against with an explicit (T) cast at the
return site. Add the same cast here for consistency and to make the
intent explicit. Covered by the existing EntityDataFetcherSpec
"test get"/"test pagination" specs, which assert on the returned list.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…kers

CustomInterceptorInvoker#invoke and ProvidedInterceptorInvoker#invoke
were identical 9-line fragments: resolve the operation name, run the
subclass-specific invocation, log when it returns false, return the
result. Extract the shared name/log/return steps into a
logIfPrevented(name, result) template method on the common
InterceptorInvoker base (which now carries the @Slf4j/@CompileStatic
annotations instead of each sibling declaring its own logger), and
have both invoke() overrides call it. Behavior is unchanged; the
existing Query/Mutation/CustomQuery/CustomMutation InterceptorInvoker
specs already cover both the allowed and prevented-by-interceptor
branches.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…Invoker

getFields() has been deprecated in graphql-java since 2018-12-20 in
favor of getMergedField(). InterceptorInvoker#getName() used
environment.fields[0].name (with an empty-list guard) purely to grab
the name of the current field; MergedField#getName() returns exactly
the same value (the single field's name), so swap to
getMergedField() with a null guard instead.

Updated QueryInterceptorInvokerSpec/MutationInterceptorInvokerSpec and
InterceptingDataFetcherSpec, which stubbed the now-unused getFields(),
to stub getMergedField() instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- associations was declared Map<String, Association> (raw) but
  assigned from EntityFetchOptions#getAssociations(), which returns
  Map<String, Association<?>> since the earlier raw-type cleanup.
  Parameterize the field to match.
- initializeEntity(PersistentEntity) never used its parameter - the
  entity it needs is already captured on `this.entity` by the time the
  constructor calls it. Drop the redundant parameter.
- withTransaction declared a blank `datastore` local reassigned across
  an if/else, the same "assign-in-every-branch" shape flagged
  elsewhere in this cleanup. Extract the branch into a
  resolveDatastore() helper that returns directly from each branch.

Behavior is unchanged; covered by the existing
DefaultGormDataFetcherSpec join-property tests plus every subclass's
"test get" spec, which all exercise withTransaction/resolveDatastore.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ildcard

IntelliJ flags Map<String, Association<?>> with "Type parameter '?' is
not in its bound; should extend Property" since Association<T extends
Property>. Writing the bound out explicitly
(Association<? extends Property>) looks like the obvious fix, but
Groovy's static type checker - unlike javac - treats the bounded and
unbounded wildcard forms as distinct types, so
initializeEntity()'s `this.associations = this.entityFetchOptions.associations`
(which returns Map<String, Association<?>>) fails to compile against
it. Keep the unbounded form and record why, the same treatment given
to EntityFetchOptions' raw List<Selection> earlier in this cleanup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
A response handler failure on the success path must surface as a GraphQL
error rather than be reported as a failed delete, because by that point
the instance has already been removed.
@jdaugherty

Copy link
Copy Markdown
Contributor

Rebased onto 8.1.x (the #16201 commit was already merged, so it was dropped) and dropped the commit "Simplify DeleteEntityDataFetcher.get() to build the response per branch".

Moving createResponse inside the try changed behavior: if the (user-replaceable) GraphQLDeleteResponseHandler throws while building the success response, the fetcher now catches that and returns createResponse(env, false, e), so the client is told the delete failed even though the row has already been removed. Previously the handler exception propagated as a GraphQL field error. Verified with a probe spec using a handler that throws on the success path: 8.1.x → exception propagates; PR head → [success: false, error: ...] with zero rows left.

The original structure is kept and a comment now documents why the response must be built outside the try. The remaining fetcher/interceptor commits are unchanged. :grails-data-graphql-core:test and codeStyle pass on the new head.

@jdaugherty
jdaugherty force-pushed the refactor/graphql-fetcher branch from beb5efa to b048d0a Compare September 30, 2026 14:47
@jdaugherty
jdaugherty merged commit ce9f034 into 8.1.x Sep 30, 2026
14 of 15 checks passed
@jdaugherty
jdaugherty deleted the refactor/graphql-fetcher branch September 30, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants