Skip to content

feat(fdc): Add execute_graphql signatures and integration test suite - #970

Open
mk2023 wants to merge 7 commits into
winefrom
barolo-seed
Open

feat(fdc): Add execute_graphql signatures and integration test suite#970
mk2023 wants to merge 7 commits into
winefrom
barolo-seed

Conversation

@mk2023

@mk2023 mk2023 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Added execute_graphql and execute_graphql_read method signatures and docstrings to DataConnect and _DataConnectApiClient. Expanded unit test coverage in tests/test_data_connect.py for payload formatting, options validation, and error bubbling, and introduced a comprehensive integration test suite in integration/test_data_connect.py translated from Node.js Admin SDK integration tests.

mk2023 added 5 commits July 20, 2026 14:09
Implemented _make_gql_request on _DataConnectApiClient to execute and handle responses/errors for GraphQL operations. Added corresponding unit tests in tests/test_data_connect.py.
Refactored _parse_graphql_response and added robust recursive type deserialization to _DataConnectApiClient.

- Implemented _deserialize_type and _deserialize_dataclass helper methods to support nested dataclasses, generic lists (List[T]), generic dictionaries (Dict[K, V]), Unions (Union[...]), Enums, and primitive casting.
- Enhanced _make_gql_request error handling to prevent silent error swallowing when the errors key is present.
- Added comprehensive unit test coverage in tests/test_data_connect.py.
…helper

- Introduced QueryError subclass of FirebaseError for Data Connect GraphQL query/mutation errors and exposed it in __all__.
- Extracted _check_graphql_errors helper method on _DataConnectApiClient.
- Updated error handling for non-dictionary response payloads in _parse_graphql_response to raise InternalError.
- Note: Did not edit parse_graphql_response because we are waiting on whether this will even be a function or not.
…nt instantiation

- Removed output deserialization helpers (_extract_actual_type, _deserialize_type, _deserialize_dataclass) to return raw JSON payload dictionaries (ExecuteGraphqlResponse.data), aligning Data Connect with Firestore and Realtime Database patterns for user-defined schemas.
- Updated DataConnect.__init__ to immediately instantiate _DataConnectApiClient for consistency with Node.js and other Python Admin SDK services.
- Updated test suite in tests/test_data_connect.py to cover raw response parsing and immediate client instantiation.
Added execute_graphql and execute_graphql_read method signatures and docstrings to DataConnect and _DataConnectApiClient. Also introduced a comprehensive integration test suite in integration/test_data_connect.py translated from Node.js Admin SDK integration tests.

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

Copy link
Copy Markdown

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 introduces execute_graphql and execute_graphql_read methods to the DataConnect client, along with corresponding integration and unit tests. The review feedback highlights that several of these new methods are left unimplemented (raising NotImplementedError) and provides their implementation details. Additionally, the reviewer identifies a critical type-checking bug in the validation logic when variables_type is Any, and points out a mismatch in a test assertion message.

Comment thread firebase_admin/dataconnect.py
Comment thread firebase_admin/dataconnect.py
Comment thread firebase_admin/dataconnect.py
Comment thread tests/test_data_connect.py

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

in progress, leaving comments early - have to look at test cases still

raise ValueError("connector cannot be empty")


class Impersonation(dict):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

just realizing this now but IIUC, because there's no constructor defined here a default one is available for users to call directly

we should make sure that:

  1. we call out in documentation it's preferred that you use the static factory methods
  2. if they DO call the constructor, we should strictly enforce that they choose a single configuration - they can either provide unauthenticated=True or auth_claims=auth_claims

@mk2023 mk2023 Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! _validate_impersonation_options extensively validates raw dictionary inputs passed directly to GraphqlOptions(impersonate={...}), but adding validation in Impersonation.__init__ handles direct class instantiation early.

I've updated Impersonation:

  • Updated docstring to highlight static factory methods (unauthenticated() / authenticated()).
  • Added an explicit __init__ constructor validating unauthenticated vs auth_claims (and handling both auth_claims and authClaims).
  • Added unit tests in TestImpersonation covering all constructor validation scenarios.

Comment thread firebase_admin/dataconnect.py
Comment thread firebase_admin/dataconnect.py
Comment thread firebase_admin/dataconnect.py

@pytest.fixture(autouse=True)
def setup_teardown_db(default_app):
"""Sets initial database state before each test and cleans up after."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ah, this was a bad practice that we did in the admin node SDK - we haven't tested these functions yet, so how could we possibly use them to initialize the database?

instead, WDYT of this - we should seed the database using some already-tested thing... maybe the firebase CLI? i'll look more into this, feel free to as well and drop some ideas

@mk2023 mk2023 Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I understand why that isn't the most honest testing method!

If we use the Node.js SDK (or Firebase CLI) to seed the database, we would have to introduce external Node.js subprocess dependencies into pytest.

Instead, what do you think about using raw requests.post() calls directly against the emulator URL inside setup_teardown_db? This way we can seed the database via raw HTTP POST requests without invoking any firebase-admin-python SDK methods while keeping the test suite 100% Python-native.

Added an explicit __init__ constructor to Impersonation to validate parameter configurations at object instantiation time. Enforced choosing either unauthenticated=True or auth_claims, with support for both auth_claims (snake_case) and authClaims (camelCase). Updated class docstring to recommend factory methods. Also added unit test suite TestImpersonation in tests/test_data_connect.py.
@mk2023
mk2023 changed the base branch from barolo to wine July 29, 2026 07:00
@mk2023
mk2023 marked this pull request as ready for review July 29, 2026 07:01
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.

2 participants