Skip to content

Commit 56ef587

Browse files
author
FOLUSO ONATEMOWO
committed
Replaced some urls present in the executeMutation unit tests and cleaned up some unnecessary comments.
1 parent 31bdd7a commit 56ef587

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/data-connect/data-connect-api-client-internal.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class DataConnectApiClient {
102102
}
103103

104104
/**
105-
* Execute pre-existing <QueryResult<Data, Variables>> read-only queries
105+
* Execute pre-existing read-only queries <QueryResult<Data, Variables>>
106106
* @param options - GraphQL Options
107107
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
108108
* @throws FirebaseDataConnectError
@@ -113,7 +113,7 @@ export class DataConnectApiClient {
113113
return this.executeOperationHelper(EXECUTE_QUERY_ENDPOINT,options);
114114
}
115115
/**
116-
* Execute pre-existing <MutationResult<Data, Variables>> read and write queries
116+
* Execute pre-existing read and write queries <MutationResult<Data, Variables>>
117117
* @param options - GraphQL Options
118118
* @returns A promise that fulfills with a `ExecuteGraphqlResponse`.
119119
* @throws FirebaseDataConnectError
@@ -153,7 +153,6 @@ export class DataConnectApiClient {
153153
DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT,
154154
'GraphqlOptions should be a non-null object');
155155
}
156-
//Recent addition
157156
if (typeof options !== 'undefined') {
158157
if (!validator.isNonNullObject(options)) {
159158
throw new FirebaseDataConnectError(

src/data-connect/data-connect.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ export class DataConnect {
8484
query: string,
8585
options?: GraphqlOptions<Variables>,
8686
): Promise<ExecuteGraphqlResponse<GraphqlResponse>> {
87-
// if ("connector" in this.connectorConfig){
88-
// throw new FirebaseDataConnectError(DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT,'executeGraphql does not require a connector');
89-
// }
9087
return this.client.executeGraphql(query, options);
9188
}
9289

@@ -102,9 +99,6 @@ export class DataConnect {
10299
query: string,
103100
options?: GraphqlOptions<Variables>,
104101
): Promise<ExecuteGraphqlResponse<GraphqlResponse>> {
105-
// if ("connector" in this.connectorConfig){
106-
// throw new FirebaseDataConnectError(DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT,'executeGraphqlRead does not require a connector');
107-
// }
108102
return this.client.executeGraphqlRead(query, options);
109103
}
110104

@@ -214,7 +208,7 @@ export class DataConnect {
214208
*/
215209
public mutationRef<Data, Variables>(name: string, variables?: Variables): MutationRef<Data, Variables> {
216210
if (!("connector" in this.connectorConfig)){
217-
throw new FirebaseDataConnectError(DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT,'executeQuery requires a connector');
211+
throw new FirebaseDataConnectError(DATA_CONNECT_ERROR_CODE_MAPPING.INVALID_ARGUMENT,'executeMutation requires a connector');
218212
}
219213
return new MutationRef(this, name, variables as Variables, this.client);
220214
}

test/unit/data-connect/data-connect-api-client-internal.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('DataConnectApiClient', () => {
7474
const connectorConfig_with_connector: ConnectorConfig = {
7575
location: 'us-west2',
7676
serviceId: 'my-service',
77-
connector: 'mock-connector' //this is fake, I need to verify where to put it officially within mock.ts perhaps- still unsure
77+
connector: 'mock-connector'
7878
};
7979

8080
const clientWithoutProjectId = new DataConnectApiClient(
@@ -274,7 +274,7 @@ describe('DataConnectApiClient', () => {
274274
expect(resp.data.users).to.deep.equal(TEST_RESPONSE.data.users);
275275
expect(stub).to.have.been.calledOnce.and.calledWith({
276276
method: 'POST',
277-
url: `https://firebasedataconnect.googleapis.com/v1alpha/projects/test-project/locations/${connectorConfig.location}/services/${connectorConfig.serviceId}:executeGraphql`,
277+
url: `https://firebasedataconnect.googleapis.com/v1alpha/projects/test-project/locations/${connectorConfig_with_connector.location}/services/${connectorConfig_with_connector.serviceId}:executeGraphql`,
278278
headers: EXPECTED_HEADERS,
279279
data: { query: 'query' }
280280
});
@@ -290,7 +290,7 @@ describe('DataConnectApiClient', () => {
290290
.then(() => {
291291
expect(stub).to.have.been.calledOnce.and.calledWith({
292292
method: 'POST',
293-
url: `http://localhost:9399/v1alpha/projects/test-project/locations/${connectorConfig.location}/services/${connectorConfig.serviceId}:executeGraphql`,
293+
url: `http://localhost:9399/v1alpha/projects/test-project/locations/${connectorConfig_with_connector.location}/services/${connectorConfig_with_connector.serviceId}:executeGraphql`,
294294
headers: EMULATOR_EXPECTED_HEADERS,
295295
data: { query: 'query' }
296296
});
@@ -300,7 +300,6 @@ describe('DataConnectApiClient', () => {
300300
});
301301

302302
describe('executeMutation', () => {
303-
//what if there's no project id and also there's no connector, what error would that be? -> should error the connector first because you won't even reach the endpoint to find out if there's a project id or not
304303
it('should reject when project id is not available', () => {
305304
return clientWithoutProjectId_with_connector.executeMutation({operationName: 'getById'})
306305
.should.eventually.be.rejectedWith(noProjectId);
@@ -322,7 +321,7 @@ describe('DataConnectApiClient', () => {
322321
);
323322
});
324323
});
325-
//could this pass as a null object, also what if the wrong operaton was passed in, would it be handled in another test- say integration?
324+
326325
it('should throw an error if there is no operationName', async () => {
327326
await expect(apiClient_with_connector.executeMutation({})).to.be.rejectedWith(
328327
FirebaseDataConnectError,

0 commit comments

Comments
 (0)