Skip to content

Conversation

stephenarosaj
Copy link
Contributor

API Changes

  • Added executeQuery() and executeMutation() to src/data-connect/data-connect.ts. These allow users to call deployed operations with impersonated auth credentials.

Testing

  • New unit tests added which match the coverage of existing executeGraphql* APIs
  • New integration tests added which more than match the coverage of existing executeGraphql* APIs

@stephenarosaj stephenarosaj marked this pull request as ready for review September 17, 2025 22:47
@stephenarosaj
Copy link
Contributor Author

Note:

The integration tests have a huge diff because I moved the existing tests under a new parent describe(), and so their indentation level was increased. Existing tests were not changed in this PR.

@stephenarosaj
Copy link
Contributor Author

Forgot a few changes! Didn't know that you could close and re-open :P thanks Yuchen!

@stephenarosaj
Copy link
Contributor Author

wait - need to privatize the execute API, execution should come from operation refs (in a future PR)

@stephenarosaj stephenarosaj reopened this Sep 25, 2025
@stephenarosaj stephenarosaj added the release:stage Stage a release candidate label Sep 25, 2025

/** The Firebase Data Connect backend connector URL format. */
const FIREBASE_DATA_CONNECT_CONNECTORS_URL_FORMAT =
'https://autopush-firebasedataconnect.sandbox.googleapis.com/{version}/projects/{projectId}/locations/{locationId}/services/{serviceId}/connectors/{connectorId}:{endpointId}';
Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving a comment to block merging on these changes

this.connectorConfig.connector,
);
return this.makeGqlRequest<GraphqlResponse>(url, data)
.then((resp) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get rid of this line? And can we replace this block with a try/catch?

})
const url = await this.getUrl(API_VERSION, this.connectorConfig.location, this.connectorConfig.serviceId, endpoint);
return this.makeGqlRequest<GraphqlResponse>(url, data)
.then((resp) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can get rid of this

options: GraphqlOptions<Variables>
): Promise<ExecuteGraphqlResponse<GraphqlResponse>> {
if (
typeof options.operationName === 'undefined' ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as a note, this'll change when we move things like name and options out of the GraphqlOptions field

};
let urlFormat: string;
if (useEmulator()) {
(urlParams as any).host = emulatorHost();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this more strongly typed? I'd rather we add an empty host field in urlParams than cast to any and lose type-safety

user_upsert(data: { id: "fred_id", address: "32 Elm St.", name: "Fred" })
}
mutation updateFredrickUserImpersonation @auth(level: USER) {
mutation updateFredrickUserImpersonation @auth(level: USER, insecureReason: "test") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: These changes likely require a re-deploy on the CI project

const authenticatedOptions: GraphqlOptions<unknown> =
{ operationName: 'authenticatedQuery', impersonate: { authClaims: { sub: 'authenticated-UUID' } } };

it('should reject when no operationName is provided', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are all rejections, should they be nested in a separate reject describe, like on line 308?

const stub = sandbox
.stub(HttpClient.prototype, 'send')
.resolves(utils.responseFrom(TEST_RESPONSE, 200));
return apiClient.executeQuery<UsersResponse, unknown>(unauthenticatedOptions).then((resp) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably await this

});

it('should use DATA_CONNECT_EMULATOR_HOST if set', () => {
process.env.DATA_CONNECT_EMULATOR_HOST = 'localhost:9399';
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we reset this after the test is complete?

});

it('should use DATA_CONNECT_EMULATOR_HOST if set', () => {
process.env.DATA_CONNECT_EMULATOR_HOST = 'localhost:9399';
Copy link
Contributor

Choose a reason for hiding this comment

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

Reset after?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:stage Stage a release candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants