Skip to content

Commit 2475456

Browse files
authored
chore: updates apollo-client lib with all its dependences (#418)
1 parent 297e234 commit 2475456

6 files changed

Lines changed: 59 additions & 120 deletions

File tree

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.3.3/schema.json",
33
"assist": { "actions": { "source": { "organizeImports": "on" } } },
44
"linter": {
55
"enabled": true,

e2e/scan/eol.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ describe('scan:eol e2e', () => {
9393

9494
describe('default arguments', () => {
9595
it('runs scan:eol with file flag and shows results', async () => {
96-
const { stdout } = await execAsync(`node bin/run.js scan:eol --file ${simpleSbom}`);
96+
const { stdout } = await run(`scan:eol --file ${simpleSbom}`);
9797
match(stdout, /Scan results:/, 'Should show results header');
9898
match(stdout, /1( .*)End-of-Life \(EOL\)/, 'Should show EOL count of 1');
9999
match(stdout, /total packages scanned/i, 'Should show total packages scanned');
100100
});
101101

102102
it('runs scan:eol with --json and produces valid JSON', async () => {
103-
const { stdout } = await execAsync(`node bin/run.js scan:eol --file ${simpleSbom} --json`);
103+
const { stdout } = await run(`scan:eol --file ${simpleSbom} --json`);
104104
doesNotMatch(stdout, /Scan results:/, 'Should not show results header');
105105
doesNotThrow(() => JSON.parse(stdout), 'Output should be valid JSON');
106106
});

package-lock.json

Lines changed: 32 additions & 107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
],
4141
"dependencies": {
4242
"@amplitude/analytics-node": "^1.5.21",
43-
"@apollo/client": "^3.13.8",
43+
"@apollo/client": "^4.0.9",
4444
"@cyclonedx/cdxgen": "^11.11.0",
4545
"@herodevs/eol-shared": "github:herodevs/eol-shared#v0.1.12",
4646
"@oclif/core": "^4.8.0",
@@ -110,4 +110,4 @@
110110
}
111111
},
112112
"types": "dist/index.d.ts"
113-
}
113+
}

src/api/gql-operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { gql } from '@apollo/client/core/core.cjs';
1+
import { gql } from '@apollo/client/core';
22

33
export const createReportMutation = gql`
44
mutation createReport($input: CreateEolReportInput) {

src/api/nes.client.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client/core/index.js';
1+
import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client/core';
22
import type {
33
CreateEolReportInput,
44
EolReport,
55
EolReportMutationResponse,
66
EolReportQueryResponse,
77
GetEolReportInput,
88
} from '@herodevs/eol-shared';
9+
import type { GraphQLFormattedError } from 'graphql';
910
import { config } from '../config/constants.ts';
1011
import { debugLogger } from '../service/log.svc.ts';
1112
import { stripTypename } from '../utils/strip-typename.ts';
1213
import { createReportMutation, getEolReportQuery } from './gql-operations.ts';
1314

15+
type GraphQLExecutionResult = {
16+
errors?: ReadonlyArray<GraphQLFormattedError>;
17+
};
18+
1419
export const createApollo = (uri: string) =>
1520
new ApolloClient({
1621
cache: new InMemoryCache(),
@@ -28,13 +33,17 @@ export const createApollo = (uri: string) =>
2833

2934
export const SbomScanner = (client: ReturnType<typeof createApollo>) => {
3035
return async (input: CreateEolReportInput): Promise<EolReport> => {
31-
const res = await client.mutate<EolReportMutationResponse, { input: CreateEolReportInput }>({
36+
let res: Awaited<ReturnType<typeof client.mutate<EolReportMutationResponse, { input: CreateEolReportInput }>>>;
37+
res = await client.mutate<EolReportMutationResponse, { input: CreateEolReportInput }>({
3238
mutation: createReportMutation,
3339
variables: { input },
3440
});
3541

36-
if (res?.errors?.length) {
37-
debugLogger('GraphQL errors in createReport: %o', res.errors);
42+
if (res?.error || (res as GraphQLExecutionResult)?.errors) {
43+
debugLogger(
44+
'Error returned from createReport mutation: %o',
45+
res.error || (res as GraphQLExecutionResult | undefined)?.errors,
46+
);
3847
throw new Error('Failed to create EOL report');
3948
}
4049

@@ -64,11 +73,16 @@ export const SbomScanner = (client: ReturnType<typeof createApollo>) => {
6473

6574
for (let i = 0; i < pages.length; i += config.concurrentPageRequests) {
6675
const batch = pages.slice(i, i + config.concurrentPageRequests);
67-
const batchResponses = await Promise.all(batch);
76+
let batchResponses: Awaited<
77+
ReturnType<typeof client.query<EolReportQueryResponse, { input: GetEolReportInput }>>
78+
>[];
79+
80+
batchResponses = await Promise.all(batch);
6881

6982
for (const response of batchResponses) {
70-
if (response?.errors?.length) {
71-
debugLogger('GraphQL errors in getReport query: %o', response.errors);
83+
const queryErrors = (response as GraphQLExecutionResult | undefined)?.errors;
84+
if (response?.error || queryErrors?.length || !response.data?.eol) {
85+
debugLogger('Error in getReport query response: %o', response?.error ?? queryErrors ?? response);
7286
throw new Error('Failed to fetch EOL report');
7387
}
7488

0 commit comments

Comments
 (0)