Skip to content

Commit

Permalink
chore(deps): lock file maintenance (#3860)
Browse files Browse the repository at this point in the history
* chore(deps): lock file maintenance

* ..

* Lockfile

* chore(dependencies): updated changesets for modified dependencies

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 6, 2025
1 parent ec5e3fc commit 9599d45
Show file tree
Hide file tree
Showing 23 changed files with 1,135 additions and 996 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-apollo-usage-report": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-yoga_plugin-apq-3860-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-apq": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-graphql-sse": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-yoga_plugin-jwt-3860-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-jwt": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-persisted-operations": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-response-cache": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/@graphql-yoga_plugin-sofa-3860-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-yoga/plugin-sofa": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
1 change: 1 addition & 0 deletions packages/plugins/apollo-usage-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@apollo/usage-reporting-protobuf": "^4.1.1",
"@graphql-yoga/plugin-apollo-inline-trace": "workspace:^",
"@whatwg-node/promise-helpers": "^1.2.4",
"tslib": "^2.8.1"
},
"devDependencies": {
Expand Down
111 changes: 64 additions & 47 deletions packages/plugins/apollo-usage-report/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ApolloInlineTracePluginOptions,
useApolloInstrumentation,
} from '@graphql-yoga/plugin-apollo-inline-trace';
import { handleMaybePromise, MaybePromise } from '@whatwg-node/promise-helpers';

type ApolloUsageReportOptions = ApolloInlineTracePluginOptions & {
/**
Expand Down Expand Up @@ -80,7 +81,7 @@ export function useApolloUsageReport(options: ApolloUsageReportOptions = {}): Pl
WeakMap<Request, ApolloUsageReportRequestContext>,
];

let schemaIdSet$: Promise<void> | undefined;
let schemaIdSet$: MaybePromise<void> | undefined;
let schemaId: string;
let yoga: YogaServer<Record<string, unknown>, Record<string, unknown>>;
const logger = Object.fromEntries(
Expand Down Expand Up @@ -122,10 +123,13 @@ export function useApolloUsageReport(options: ApolloUsageReportOptions = {}): Pl
},
onSchemaChange({ schema }) {
if (schema) {
schemaIdSet$ = hashSHA256(printSchema(schema), yoga.fetchAPI).then(id => {
schemaId = id;
schemaIdSet$ = undefined;
});
schemaIdSet$ = handleMaybePromise(
() => hashSHA256(printSchema(schema), yoga.fetchAPI),
id => {
schemaId = id;
schemaIdSet$ = undefined;
},
);
}
},

Expand Down Expand Up @@ -213,25 +217,31 @@ export function useApolloUsageReport(options: ApolloUsageReportOptions = {}): Pl
};
}

export async function hashSHA256(
str: string,
export function hashSHA256(
text: string,
api: {
crypto: Crypto;
TextEncoder: (typeof globalThis)['TextEncoder'];
} = globalThis,
) {
const { crypto, TextEncoder } = api;
const textEncoder = new TextEncoder();
const utf8 = textEncoder.encode(str);
const hashBuffer = await crypto.subtle.digest('SHA-256', utf8);
let hashHex = '';
for (const bytes of new Uint8Array(hashBuffer)) {
hashHex += bytes.toString(16).padStart(2, '0');
}
return hashHex;
const inputUint8Array = new api.TextEncoder().encode(text);
return handleMaybePromise(
() => api.crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array),
arrayBuf => {
const outputUint8Array = new Uint8Array(arrayBuf);

let hash = '';
for (const byte of outputUint8Array) {
const hex = byte.toString(16);
hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
}

return hash;
},
);
}

async function sendTrace(
function sendTrace(
options: ApolloUsageReportOptions,
logger: YogaLogger,
fetch: FetchAPI['fetch'],
Expand All @@ -245,36 +255,43 @@ async function sendTrace(
endpoint = DEFAULT_REPORTING_ENDPOINT,
} = options;

try {
const body = Report.encode({
header: {
agentVersion,
graphRef,
executableSchemaId: schemaId,
},
operationCount: 1,
tracesPerQuery,
}).finish();
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'content-type': 'application/protobuf',
// The presence of the api key is already checked at Yoga initialization time

'x-api-key': apiKey!,
accept: 'application/json',
},
body,
});
const responseText = await response.text();
if (response.ok) {
logger.debug('Traces sent:', responseText);
} else {
logger.error('Failed to send trace:', responseText);
}
} catch (err) {
logger.error('Failed to send trace:', err);
}
const body = Report.encode({
header: {
agentVersion,
graphRef,
executableSchemaId: schemaId,
},
operationCount: 1,
tracesPerQuery,
}).finish();
return handleMaybePromise(
() =>
fetch(endpoint, {
method: 'POST',
headers: {
'content-type': 'application/protobuf',
// The presence of the api key is already checked at Yoga initialization time

'x-api-key': apiKey!,
accept: 'application/json',
},
body,
}),
response =>
handleMaybePromise(
() => response.text(),
responseText => {
if (response.ok) {
logger.debug('Traces sent:', responseText);
} else {
logger.error('Failed to send trace:', responseText);
}
},
),
err => {
logger.error('Failed to send trace:', err);
},
);
}

function isDocumentNode(data: unknown): data is DocumentNode {
Expand Down
3 changes: 3 additions & 0 deletions packages/plugins/apq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"peerDependencies": {
"graphql-yoga": "workspace:^"
},
"dependencies": {
"@whatwg-node/promise-helpers": "^1.2.4"
},
"devDependencies": {
"@apollo/client": "3.13.1",
"crypto-hash": "3.1.0",
Expand Down
94 changes: 54 additions & 40 deletions packages/plugins/apq/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { createGraphQLError, createLRUCache, Plugin, PromiseOrValue } from 'graphql-yoga';
import { handleMaybePromise } from '@whatwg-node/promise-helpers';

export async function hashSHA256(
str: string,
export function hashSHA256(
text: string,
api: {
crypto: Crypto;
TextEncoder: (typeof globalThis)['TextEncoder'];
} = globalThis,
) {
const { crypto, TextEncoder } = api;
const textEncoder = new TextEncoder();
const utf8 = textEncoder.encode(str);
const hashBuffer = await crypto.subtle.digest('SHA-256', utf8);
let hashHex = '';
for (const bytes of new Uint8Array(hashBuffer)) {
hashHex += bytes.toString(16).padStart(2, '0');
}
return hashHex;
const inputUint8Array = new api.TextEncoder().encode(text);
return handleMaybePromise(
() => api.crypto.subtle.digest({ name: 'SHA-256' }, inputUint8Array),
arrayBuf => {
const outputUint8Array = new Uint8Array(arrayBuf);

let hash = '';
for (const byte of outputUint8Array) {
const hex = byte.toString(16);
hash += '00'.slice(0, Math.max(0, 2 - hex.length)) + hex;
}

return hash;
},
);
}

export interface APQStoreOptions {
Expand Down Expand Up @@ -80,43 +87,50 @@ export function useAPQ(options: APQOptions = {}): Plugin {
const { store = createInMemoryAPQStore(), hash = hashSHA256, responseConfig = {} } = options;

return {
async onParams({ params, setParams, fetchAPI }) {
onParams({ params, setParams, fetchAPI }) {
const persistedQueryData = decodeAPQExtension(params.extensions?.['persistedQuery']);

if (persistedQueryData === null) {
return;
}

if (params.query == null) {
const persistedQuery = await store.get(persistedQueryData.sha256Hash);
if (persistedQuery == null) {
throw createGraphQLError('PersistedQueryNotFound', {
extensions: {
http: {
status: responseConfig.forceStatusCodeOk ? 200 : 404,
},
code: 'PERSISTED_QUERY_NOT_FOUND',
},
});
}
setParams({
...params,
query: persistedQuery,
});
} else {
const expectedHash = await hash(params.query, fetchAPI);
if (persistedQueryData.sha256Hash !== expectedHash) {
throw createGraphQLError('PersistedQueryMismatch', {
extensions: {
http: {
status: responseConfig.forceStatusCodeOk ? 200 : 400,
},
code: 'PERSISTED_QUERY_MISMATCH',
},
});
}
await store.set(persistedQueryData.sha256Hash, params.query);
return handleMaybePromise(
() => store.get(persistedQueryData.sha256Hash),
persistedQuery => {
if (persistedQuery == null) {
throw createGraphQLError('PersistedQueryNotFound', {
extensions: {
http: {
status: responseConfig.forceStatusCodeOk ? 200 : 404,
},
code: 'PERSISTED_QUERY_NOT_FOUND',
},
});
}
setParams({
...params,
query: persistedQuery,
});
},
);
}
return handleMaybePromise(
() => hash(params.query!, fetchAPI),
expectedHash => {
if (persistedQueryData.sha256Hash !== expectedHash) {
throw createGraphQLError('PersistedQueryMismatch', {
extensions: {
http: {
status: responseConfig.forceStatusCodeOk ? 200 : 400,
},
code: 'PERSISTED_QUERY_MISMATCH',
},
});
}
return store.set(persistedQueryData.sha256Hash, params.query!);
},
);
},
};
}
1 change: 1 addition & 0 deletions packages/plugins/graphql-sse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"graphql-yoga": "workspace:^"
},
"dependencies": {
"@whatwg-node/promise-helpers": "^1.2.4",
"graphql-sse": "^2.0.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 9599d45

Please sign in to comment.