Skip to content

Switch query execution to a mutation and add cancellation#855

Closed
kmcginnes wants to merge 1 commit intoaws:main-query-editorfrom
kmcginnes:use-mutation
Closed

Switch query execution to a mutation and add cancellation#855
kmcginnes wants to merge 1 commit intoaws:main-query-editorfrom
kmcginnes:use-mutation

Conversation

@kmcginnes
Copy link
Collaborator

@kmcginnes kmcginnes commented Mar 28, 2025

Description

Switches away from useQuery() as the mechanism of executing the user provided query. Instead it uses useMutation().

This is to prevent unintended executions of the query. useQuery is designed to be executed when React renders the view. But that is not desired in this case. Especially if the user happens to be running an actual Gremlin mutation query. That could lead to multiple nodes created/modified/deleted.

The mutation version only executes when called. This means if the view is unmounted and remounted, then the query results are lost. The user must re-run the query explicitly. While I'm sure I could find a way to somehow persist these results in a way that makes sense, there's not a simple solution. So I'm kicking the can down the road to a future where that functionality is asked for explicitly.

As a result of this change, I can no longer reuse SearchResultList component. So I duplicated and modified that view for the raw query mutation. This removes the cancel button (which didn't work) and customizes the loading and error messages to be more appropriate for the context.

Also, added cancellation to the mutation.

Validation

  • Tested with Neptune verifying that the query only executes when the form is submitted.
  • Tested cancellation

Related Issues

Check List

  • I confirm that my contribution is made under the terms of the Apache 2.0
    license.
  • I have run pnpm checks to ensure code compiles and meets standards.
  • I have run pnpm test to check if all tests are passing.
  • I have covered new added functionality with unit tests if necessary.
  • I have added an entry in the Changelog.md.

@kmcginnes kmcginnes marked this pull request as ready for review March 28, 2025 22:34
@kmcginnes kmcginnes marked this pull request as draft April 8, 2025 14:29
@kmcginnes
Copy link
Collaborator Author

Holding off on this PR until after the release

@codecov
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 2.59259% with 263 lines in your changes missing coverage. Please review.

Project coverage is 32.52%. Comparing base (a899239) to head (a94b8b9).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...rc/modules/SearchSidebar/QuerySearchTabContent.tsx 0.00% 103 Missing and 1 partial ⚠️
...er/src/modules/SearchSidebar/SearchResultsList.tsx 0.00% 64 Missing ⚠️
...plorer/src/modules/SearchSidebar/SearchSidebar.tsx 0.00% 30 Missing ⚠️
...c/modules/SearchSidebar/FilterSearchTabContent.tsx 0.00% 26 Missing ⚠️
...s/graph-explorer/src/connector/gremlin/rawQuery.ts 21.05% 15 Missing ⚠️
...-explorer/src/connector/gremlin/gremlinExplorer.ts 9.09% 10 Missing ⚠️
...rer/src/connector/openCypher/openCypherExplorer.ts 0.00% 6 Missing ⚠️
...ph-explorer/src/connector/sparql/sparqlExplorer.ts 0.00% 4 Missing ⚠️
...h-explorer/src/core/StateProvider/useResetState.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #855      +/-   ##
==========================================
+ Coverage   30.72%   32.52%   +1.80%     
==========================================
  Files         525      527       +2     
  Lines       23627    21365    -2262     
  Branches     1408     1451      +43     
==========================================
- Hits         7259     6949     -310     
+ Misses      16241    14294    -1947     
+ Partials      127      122       -5     
Flag Coverage Δ
unittests 32.52% <2.59%> (+1.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@kmcginnes kmcginnes force-pushed the use-mutation branch 2 times, most recently from fed8122 to be1ba3a Compare May 29, 2025 23:34
@kmcginnes kmcginnes changed the base branch from main to main-query-editor May 29, 2025 23:34
@kmcginnes kmcginnes marked this pull request as ready for review May 29, 2025 23:34
@kmcginnes kmcginnes requested a review from andreachild May 29, 2025 23:36
@kmcginnes kmcginnes changed the title Use mutation Switch query execution to a mutation and add cancellation Jun 2, 2025
@kmcginnes kmcginnes mentioned this pull request Jun 2, 2025
5 tasks
@kmcginnes
Copy link
Collaborator Author

Closing this in favor of #949

@kmcginnes kmcginnes closed this Jun 2, 2025
@kmcginnes kmcginnes deleted the use-mutation branch June 27, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent multiple execution of mutation queries

1 participant