Skip to content

dataconnect(chore): use token objects instead of strings to improve type safety#8027

Merged
dconeybe merged 6 commits intomainfrom
dconeybe/dataconnect/DataConnectGrpcMetadataTokenRefactor
Apr 9, 2026
Merged

dataconnect(chore): use token objects instead of strings to improve type safety#8027
dconeybe merged 6 commits intomainfrom
dconeybe/dataconnect/DataConnectGrpcMetadataTokenRefactor

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented Apr 8, 2026

This PR refactors the internal Data Connect gRPC client and metadata handling to pass around token objects (GetAuthTokenResult, GetAppCheckTokenResult) instead of raw strings. This improves type safety and simplifies the logic for retrying requests on authentication errors, as the token retrieval and metadata construction are now more decoupled and robust.

Highlights

  • Token Object Refactoring: Replaced raw string token passing with GetAuthTokenResult and GetAppCheckTokenResult objects across DataConnectGrpcClient, DataConnectGrpcRPCs, and DataConnectGrpcMetadata.
  • Improved Retry Logic: Streamlined retryOnGrpcUnauthenticatedError in DataConnectGrpcClient to retrieve fresh tokens before retrying, ensuring that authentication failures are handled correctly with up-to-date credentials.
  • Metadata Handling Enhancements: Updated DataConnectGrpcMetadata to accept token objects directly in its get method, and added support for including authUid in scrubbed debug logs.
  • Test Suite Updates: Extensively updated unit tests and property-based tests in DataConnectGrpcClientUnitTest, DataConnectGrpcMetadataUnitTest, and DataConnectGrpcRPCsUnitTest to reflect the new token-based architecture and ensure comprehensive coverage of the refactored paths.

Changelog

Details
  • CHANGELOG.md: Added entry for the internal refactor to use token objects instead of strings.
  • DataConnectGrpcClient.kt: Updated to use token objects in execution paths and improved retryOnGrpcUnauthenticatedError to handle token refresh more effectively.
  • DataConnectGrpcMetadata.kt: Refactored get to accept token objects and updated toStructProto to include authUid in scrubbed auth token headers for better debugging.
  • DataConnectGrpcRPCs.kt: Updated executeQuery and executeMutation signatures to accept GetAuthTokenResult and GetAppCheckTokenResult.
  • DataConnectGrpcClientUnitTest.kt: Updated unit tests to verify correct token passing and retry behavior with the new object-based approach.
  • DataConnectGrpcMetadataUnitTest.kt: Refactored tests to utilize token object arbitraries and verified metadata construction with various token states.
  • DataConnectGrpcRPCsUnitTest.kt: Updated gRPC RPC tests to pass token objects and verified that they are correctly handled during execution.
  • arbs.kt: Updated DataConnectArb extension functions to support generating token results and updated dataConnectGrpcMetadata arb.
  • tuples.kt: Introduced the MultipleValues interface to simplify collection-based operations on custom tuple types used in property testing.

…enResult objects instead of raw strings for better type safety [skip actions]
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented Apr 8, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the DataConnect gRPC client to use token objects instead of strings for authentication and AppCheck. It updates the gRPC metadata handling to include auth UIDs in logs and improves the robustness of the gRPC retry logic by passing tokens explicitly. I have one suggestion regarding the putHeaders function to ensure consistency in how auth UIDs are handled across different logging methods.

@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented Apr 9, 2026

/gemini review

@dconeybe dconeybe changed the title dataconnect(chore): Pass around token objects instead of strings for better type safety dataconnect(chore): use token objects instead of strings to improve type safety Apr 9, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the DataConnect gRPC client to centralize authentication and app check token handling. Token fetching and refresh logic are now managed within DataConnectGrpcClient's retryOnGrpcUnauthenticatedError method, which passes tokens explicitly to DataConnectGrpcRPCs and DataConnectGrpcMetadata. This involved updating method signatures, removing token fetching logic from DataConnectGrpcMetadata, and adjusting constructor parameters. Corresponding test files were updated to reflect these changes, including new test utilities for token handling. A CHANGELOG.md entry was added. Feedback includes a question about the intentional removal of fetchPolicy validation, a suggestion for cleaner authUid logging, and a redundant iterator() extension function in test utilities.

@dconeybe dconeybe marked this pull request as ready for review April 9, 2026 13:28
@dconeybe dconeybe merged commit 554fe26 into main Apr 9, 2026
43 checks passed
@dconeybe dconeybe deleted the dconeybe/dataconnect/DataConnectGrpcMetadataTokenRefactor branch April 9, 2026 16:49
@github-actions github-actions bot mentioned this pull request Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants