Skip to content

Commit fe12214

Browse files
committed
FAI-14503: Batch Hermes GraphQL queries
1. lint
1 parent f06d6bc commit fe12214

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

test/.eslintrc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/graphql-client.test.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'fs-extra';
2+
import pino from 'pino';
23

3-
import {Schema} from '../src';
4+
import {Schema, SchemaLoader} from '../src';
45
import {
56
batchIterator,
67
GraphQLBackend,
@@ -15,7 +16,8 @@ import {
1516
UpsertBuffer,
1617
} from '../src/graphql/client/graphql-client';
1718
import {Operation, UpdateRecord} from '../src/graphql/client/types';
18-
import pino from 'pino';
19+
20+
/*eslint max-len: ["error", { "code": 120 }]*/
1921

2022
describe('graphql-client', () => {
2123
test('basic batch mutation', () => {
@@ -207,10 +209,12 @@ describe('graphql-client write batch upsert', () => {
207209
}
208210
}`);
209211
const record1 = JSON.parse(
210-
'{"name":"foo","uid":"foo","repository":{"name":"metis","uid":"metis","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
212+
'{"name":"foo","uid":"foo","repository":{"name":"metis","uid":"metis",' +
213+
'"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
211214
);
212215
const record2 = JSON.parse(
213-
'{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
216+
'{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes",' +
217+
'"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
214218
);
215219
let queries = 0;
216220
const backend: GraphQLBackend = {
@@ -226,9 +230,8 @@ describe('graphql-client write batch upsert', () => {
226230
return Promise.resolve(res2);
227231
} else if (query.startsWith('mutation { insert_vcs_Branch')) {
228232
return Promise.resolve(res3);
229-
} else {
230-
throw new Error('unexpected query ' + query);
231233
}
234+
throw new Error('unexpected query ' + query);
232235
},
233236
};
234237
const client = new GraphQLClient(
@@ -306,7 +309,8 @@ describe('graphql-client write batch upsert', () => {
306309
const records = [
307310
JSON.parse('{"name":"foo","uid":"foo"}'),
308311
JSON.parse(
309-
'{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes","organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
312+
'{"name":"main","uid":"main","repository":{"name":"hermes","uid":"hermes",' +
313+
'"organization":{"uid":"faros-ai","source":"GitHub"}},"source":"GitHub"}'
310314
),
311315
];
312316
let queries = 0;
@@ -360,9 +364,8 @@ describe('graphql-client write batch upsert', () => {
360364
queries++;
361365
if (query.startsWith('mutation { insert_vcs_Organization')) {
362366
return Promise.resolve(res1);
363-
} else {
364-
throw new Error('unexpected query ' + query);
365367
}
368+
throw new Error('unexpected query ' + query);
366369
},
367370
};
368371
const client = new GraphQLClient(
@@ -441,7 +444,9 @@ describe('graphql-client write batch upsert', () => {
441444
}`);
442445
const responses = [res1, res2, res3, res4];
443446
const record1 = JSON.parse(
444-
'{"userTool":{"user":{"uid":"dbruno21","source":"GitHub"},"organization":{"uid":"princode-ar","source":"GitHub"},"tool":{"category":"GitHubCopilot","detail":""}},"usedAt":"2021-10-14T00:53:33-06:00"}'
447+
'{"userTool":{"user":{"uid":"dbruno21","source":"GitHub"},' +
448+
'"organization":{"uid":"princode-ar","source":"GitHub"},' +
449+
'"tool":{"category":"GitHubCopilot","detail":""}},"usedAt":"2021-10-14T00:53:33-06:00"}'
445450
);
446451
let queries = 0;
447452
const backend: GraphQLBackend = {
@@ -465,7 +470,7 @@ describe('graphql-client write batch upsert', () => {
465470
await client.flush();
466471
expect(queries).toEqual(4);
467472
});
468-
test('mergeByPrimaryKey', async () => {
473+
test('mergeByPrimaryKey', () => {
469474
const users = [
470475
{
471476
uid: 'tovbinm',
@@ -517,7 +522,7 @@ describe('graphql-client write batch upsert', () => {
517522
const primaryKeys = ['uid', 'source'];
518523
expect(mergeByPrimaryKey(users, primaryKeys)).toMatchSnapshot();
519524
});
520-
test('mergeByPrimaryKey - object value', async () => {
525+
test('mergeByPrimaryKey - object value', () => {
521526
const objs = [
522527
{
523528
uid: 'tovbinm',
@@ -726,14 +731,16 @@ describe('graphql-client write batch upsert', () => {
726731
model: 'vcs_PullRequest',
727732
origin: 'my-origin',
728733
data: JSON.parse(
729-
'{"number":2,"uid":"2","repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
734+
'{"number":2,"uid":"2","repository":{"name":"repo1","uid":"repo1",' +
735+
'"organization":{"uid":"playg","source":"Bitbucket"}}}'
730736
),
731737
},
732738
{
733739
model: 'vcs_Commit',
734740
origin: 'my-origin',
735741
data: JSON.parse(
736-
'{"sha":"b500332b58c74fc15302c8961e54facf66c16c44","uid":"b500332b58c74fc15302c8961e54facf66c16c44","repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
742+
'{"sha":"b500332b58c74fc15302c8961e54facf66c16c44","uid":"b500332b58c74fc15302c8961e54facf66c16c44",' +
743+
'"repository":{"name":"repo1","uid":"repo1","organization":{"uid":"playg","source":"Bitbucket"}}}'
737744
),
738745
},
739746
];
@@ -992,7 +999,7 @@ describe('graphql-client write batch upsert', () => {
992999
});
9931000

9941001
describe('graphql-client write batch updates', () => {
995-
const schemaLoader = {
1002+
const schemaLoader: SchemaLoader = {
9961003
async loadSchema(): Promise<Schema> {
9971004
return await fs.readJson('test/resources/hasura-ce-schema.json', {
9981005
encoding: 'utf-8',
@@ -1049,7 +1056,7 @@ describe('graphql-client write batch updates', () => {
10491056
});
10501057

10511058
describe('upsert buffer', () => {
1052-
test('basic', async () => {
1059+
test('basic', () => {
10531060
const buf = new UpsertBuffer();
10541061
buf.add({model: 'm1', object: {}, foreignKeys: {}});
10551062
expect(buf.size()).toEqual(1);
@@ -1067,11 +1074,11 @@ describe('upsert buffer', () => {
10671074
});
10681075

10691076
describe('graphql-client utilities', () => {
1070-
test('serialize', async () => {
1077+
test('serialize', () => {
10711078
expect(serialize({z: 1, a: 'bar'})).toEqual('a:bar|z:1');
10721079
expect(serialize({})).toEqual('');
10731080
});
1074-
test('strictPick', async () => {
1081+
test('strictPick', () => {
10751082
expect(strictPick({z: 0, a: 'bar'}, ['z', 'b'])).toEqual({z: 0, b: 'null'});
10761083
expect(strictPick({z: 1, a: 'bar'}, ['z', 'b'])).toEqual({z: 1, b: 'null'});
10771084
expect(strictPick({z: 1, a: 'bar'}, ['b'])).toEqual({b: 'null'});
@@ -1251,18 +1258,18 @@ describe('groupByKeys', () => {
12511258
});
12521259

12531260
describe('toPostgresArrayLiteral', () => {
1254-
test('strings', async () => {
1255-
expect(toPostgresArrayLiteral(['a', 'b', 'c'])).toEqual(`{"a","b","c"}`);
1256-
expect(toPostgresArrayLiteral(['a', '', 'c'])).toEqual(`{"a","","c"}`);
1257-
expect(toPostgresArrayLiteral(['a', null, 'c'])).toEqual(`{"a",NULL,"c"}`);
1261+
test('strings', () => {
1262+
expect(toPostgresArrayLiteral(['a', 'b', 'c'])).toEqual('{"a","b","c"}');
1263+
expect(toPostgresArrayLiteral(['a', '', 'c'])).toEqual('{"a","","c"}');
1264+
expect(toPostgresArrayLiteral(['a', null, 'c'])).toEqual('{"a",NULL,"c"}');
12581265
expect(toPostgresArrayLiteral(['a', undefined, 'c'])).toEqual(
1259-
`{"a",NULL,"c"}`
1266+
'{"a",NULL,"c"}'
12601267
);
12611268
});
1262-
test('numbers', async () => {
1263-
expect(toPostgresArrayLiteral([1, 2, 3])).toEqual(`{1,2,3}`);
1264-
expect(toPostgresArrayLiteral([1, null, 3])).toEqual(`{1,NULL,3}`);
1265-
expect(toPostgresArrayLiteral([1, undefined, 3])).toEqual(`{1,NULL,3}`);
1266-
expect(toPostgresArrayLiteral([1, 0, 3])).toEqual(`{1,0,3}`);
1269+
test('numbers', () => {
1270+
expect(toPostgresArrayLiteral([1, 2, 3])).toEqual('{1,2,3}');
1271+
expect(toPostgresArrayLiteral([1, null, 3])).toEqual('{1,NULL,3}');
1272+
expect(toPostgresArrayLiteral([1, undefined, 3])).toEqual('{1,NULL,3}');
1273+
expect(toPostgresArrayLiteral([1, 0, 3])).toEqual('{1,0,3}');
12671274
});
12681275
});

0 commit comments

Comments
 (0)