Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adjust persisted document id format for specification #5318

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-tests/tests/api/app-deployments.spec.ts
Original file line number Diff line number Diff line change
@@ -1858,7 +1858,7 @@ test('app deployment usage reporting', async () => {
contextValue: { request },
},
{},
'app-name/app-version/aaa',
'app-name~app-version~aaa',
);

await waitFor(5000);
8 changes: 4 additions & 4 deletions packages/libraries/apollo/tests/persisted-documents.spec.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ test('use persisted documents (GraphQL over HTTP "documentId")', async () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});
expect(response.status).toBe(200);
@@ -112,7 +112,7 @@ test('persisted document not found (GraphQL over HTTP "documentId")', async () =
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});

@@ -265,7 +265,7 @@ test('usage reporting for persisted document', async () => {
{
metadata: {},
operationMapKey: 'ace78a32bbf8a79071356e5d5b13c5c83baf4e14',
persistedDocumentHash: 'client-name/client-version/hash',
persistedDocumentHash: 'client-name~client-version~hash',
},
]);

@@ -334,7 +334,7 @@ test('usage reporting for persisted document', async () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});
expect(response.status).toBe(200);
4 changes: 3 additions & 1 deletion packages/libraries/core/src/client/persisted-documents.ts
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@ export function createPersistedDocuments(config: PersistedDocumentsConfiguration
return document;
}

const response = await fetch(config.cdn.endpoint + '/apps/' + documentId, {
const cdnHttpId = documentId.replaceAll('~', '/');

const response = await fetch(config.cdn.endpoint + '/apps/' + cdnHttpId, {
method: 'GET',
headers: {
'X-Hive-CDN-Key': config.cdn.accessToken,
16 changes: 8 additions & 8 deletions packages/libraries/yoga/tests/persisted-documents.spec.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ test('use persisted documents (GraphQL over HTTP "documentId")', async () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});

@@ -103,7 +103,7 @@ test('use persisted documents (GraphQL over HTTP "documentId") real thing', asyn
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});

@@ -152,7 +152,7 @@ test('persisted document not found (GraphQL over HTTP "documentId")', async () =
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});

@@ -308,7 +308,7 @@ test('use persisted documents for subscription (GraphQL over HTTP "documentId")'
Accept: 'text/event-stream',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});

@@ -363,7 +363,7 @@ test('usage reporting for persisted document', async () => {
{
metadata: {},
operationMapKey: 'ace78a32bbf8a79071356e5d5b13c5c83baf4e14',
persistedDocumentHash: 'client-name/client-version/hash',
persistedDocumentHash: 'client-name~client-version~hash',
},
]);

@@ -427,7 +427,7 @@ test('usage reporting for persisted document', async () => {
'Content-Type': 'application/json',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});
expect(response.status).toBe(200);
@@ -476,7 +476,7 @@ test('usage reporting for persisted document (subscription)', async () => {
{
metadata: {},
operationMapKey: '74cf03b67c3846231d04927b02e1fca45e727223',
persistedDocumentHash: 'client-name/client-version/hash',
persistedDocumentHash: 'client-name~client-version~hash',
},
]);

@@ -553,7 +553,7 @@ test('usage reporting for persisted document (subscription)', async () => {
Accept: 'text/event-stream',
},
body: JSON.stringify({
documentId: 'client-name/client-version/hash',
documentId: 'client-name~client-version~hash',
}),
});
expect(response.status).toBe(200);
4 changes: 2 additions & 2 deletions packages/services/usage/src/usage-processor-2.ts
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ export function usageProcessorV2(

let client: ClientMetadata | undefined;
if (operation.persistedDocumentHash) {
const [name, version] = operation.persistedDocumentHash.split('/');
const [name, version] = operation.persistedDocumentHash.split('~');
client = {
name,
version,
@@ -259,7 +259,7 @@ const MetadataSchema = tb.Type.Object(
const PersistedDocumentHash = tb.Type.String({
title: 'PersistedDocumentHash',
// appName/appVersion/hash
pattern: '^[a-zA-Z0-9_-]{1,64}\\/[a-zA-Z0-9._-]{1,64}\\/([A-Za-z]|[0-9]|_){1,128}$',
pattern: '^[a-zA-Z0-9_-]{1,64}~[a-zA-Z0-9._-]{1,64}~([A-Za-z]|[0-9]|_){1,128}$',
});

/** Query + Mutation */
2 changes: 1 addition & 1 deletion packages/web/app/src/env/frontend.ts
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ function buildConfig() {
nodeEnv: base.NODE_ENV,
graphql: {
persistedOperationsPrefix:
base.GRAPHQL_PERSISTED_OPERATIONS === '1' ? `hive-app/${base.RELEASE}/` : null,
base.GRAPHQL_PERSISTED_OPERATIONS === '1' ? `hive-app~${base.RELEASE}~` : null,
},
zendeskSupport: base.ZENDESK_SUPPORT === '1',
migrations: {
Original file line number Diff line number Diff line change
@@ -335,7 +335,7 @@ Content-Type: application/json
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"documentId": "<app_name>/<app_version>/<document_hash>"}' \
-d '{"documentId": "<app_name>~<app_version>~<document_hash>"}' \
http://localhost:4000/graphql
```

2 changes: 1 addition & 1 deletion packages/web/docs/src/pages/docs/specs/usage-reports.md
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ export interface Metadata {
"persistedDocumentHash": {
"type": "string",
"title": "PersistedDocumentHash",
"pattern": "^[a-zA-Z0-9_-]{1,64}\\/[a-zA-Z0-9._-]{1,64}\\/([A-Za-z]|[0-9]|_){1,128}$"
"pattern": "^[a-zA-Z0-9_-]{1,64}~[a-zA-Z0-9._-]{1,64}~([A-Za-z]|[0-9]|_){1,128}$"
}
},
"required": ["timestamp", "operationMapKey", "execution"]
Loading