Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 1eda8ff

Browse files
feat: accept apiEndpoint override (#455)
1 parent 89f58f8 commit 1eda8ff

5 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"types": "dtsd bigquery v2 > ./src/types.d.ts"
4949
},
5050
"dependencies": {
51-
"@google-cloud/common": "^1.0.0",
51+
"@google-cloud/common": "^2.0.0",
5252
"@google-cloud/paginator": "^1.0.0",
5353
"@google-cloud/promisify": "^1.0.0",
5454
"arrify": "^2.0.0",

‎src/index.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ export interface BigQueryOptions extends common.GoogleAuthOptions {
194194
autoRetry?: boolean;
195195
maxRetries?: number;
196196
location?: string;
197+
/**
198+
* The API endpoint of the service used to make requests.
199+
* Defaults to `www.googleapis.com`.
200+
*/
201+
apiEndpoint?: string;
197202
}
198203

199204
/**
@@ -238,10 +243,11 @@ export class BigQuery extends common.Service {
238243
getDatasetsStream: (options?: GetDatasetsOptions) => ResourceStream<Dataset>;
239244
getJobsStream: (options?: GetJobsOptions) => ResourceStream<Job>;
240245

241-
constructor(options?: BigQueryOptions) {
242-
options = options || {};
246+
constructor(options: BigQueryOptions = {}) {
247+
options.apiEndpoint = options.apiEndpoint || 'www.googleapis.com';
243248
const config = {
244-
baseUrl: 'https://www.googleapis.com/bigquery/v2',
249+
apiEndpoint: options.apiEndpoint,
250+
baseUrl: `https://${options.apiEndpoint}/bigquery/v2`,
245251
scopes: ['https://www.googleapis.com/auth/bigquery'],
246252
packageJson: require('../../package.json'),
247253
};

‎src/table.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,9 @@ class Table extends common.ServiceObject {
14021402
} as {},
14031403
request: {
14041404
uri: format('{base}/{projectId}/jobs', {
1405-
base: 'https://www.googleapis.com/upload/bigquery/v2/projects',
1405+
base: `https://${
1406+
this.bigQuery.apiEndpoint
1407+
}/upload/bigquery/v2/projects`,
14061408
projectId: this.bigQuery.projectId,
14071409
}),
14081410
},

‎test/index.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import * as proxyquire from 'proxyquire';
3030
import * as sinon from 'sinon';
3131
import * as uuid from 'uuid';
3232

33-
import {BigQueryDate, Dataset, Job, Query, Table} from '../src';
33+
import {BigQueryDate, Dataset, Job, Table} from '../src';
3434
import {JobOptions} from '../src/job';
3535
import {TableField} from '../src/table';
3636

@@ -186,12 +186,23 @@ describe('BigQuery', () => {
186186
);
187187
});
188188

189+
it('should allow overriding the apiEndpoint', () => {
190+
const apiEndpoint = 'not.real.local';
191+
bq = new BigQuery({
192+
apiEndpoint,
193+
});
194+
const calledWith = bq.calledWith_[0];
195+
assert.strictEqual(
196+
calledWith.baseUrl,
197+
`https://${apiEndpoint}/bigquery/v2`
198+
);
199+
});
200+
189201
it('should capture any user specified location', () => {
190202
const bq = new BigQuery({
191203
projectId: PROJECT_ID,
192204
location: LOCATION,
193205
});
194-
195206
assert.strictEqual(bq.location, LOCATION);
196207
});
197208

‎test/table.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
JobLoadMetadata,
4141
Table,
4242
TableMetadata,
43-
TableOptions,
4443
ViewDefinition,
4544
} from '../src/table';
4645
import bigquery from '../src/types';
@@ -113,6 +112,7 @@ describe('BigQuery/Table', () => {
113112
job: (id: string) => {
114113
return {id};
115114
},
115+
apiEndpoint: 'www.googleapis.com',
116116
request: util.noop,
117117
},
118118
};

0 commit comments

Comments
 (0)