From 3082d63948ae18fb2c93c9f3f30bf0cca2a18919 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Fri, 29 Dec 2023 14:48:04 +0800 Subject: [PATCH] fix: use absolute path in gql client (#5454) --- packages/frontend/graphql/src/index.ts | 15 +++++++++++++-- packages/frontend/templates/templates.gen.ts | 2 +- .../frontend/workspace/src/impl/cloud/blob.ts | 9 +-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/frontend/graphql/src/index.ts b/packages/frontend/graphql/src/index.ts index b6ebaa7ed7..7a4a44387c 100644 --- a/packages/frontend/graphql/src/index.ts +++ b/packages/frontend/graphql/src/index.ts @@ -2,8 +2,19 @@ export * from './fetcher'; export * from './graphql'; export * from './schema'; export * from './utils'; -import '@affine/env/global'; + +import { setupGlobal } from '@affine/env/global'; import { gqlFetcherFactory } from './fetcher'; -export const fetcher = gqlFetcherFactory('/graphql'); +setupGlobal(); + +export function getBaseUrl(): string { + if (environment.isDesktop) { + return runtimeConfig.serverUrlPrefix; + } + const { protocol, hostname, port } = window.location; + return `${protocol}//${hostname}${port ? `:${port}` : ''}`; +} + +export const fetcher = gqlFetcherFactory(getBaseUrl() + '/graphql'); diff --git a/packages/frontend/templates/templates.gen.ts b/packages/frontend/templates/templates.gen.ts index 7019cb52d7..7188531ffb 100644 --- a/packages/frontend/templates/templates.gen.ts +++ b/packages/frontend/templates/templates.gen.ts @@ -26,4 +26,4 @@ export const onboarding = { '9iIScyvuIB_kUKbs1AYOQ.snapshot.json': json_9, '0nee_XzkrN23Xy7HMoXL-.snapshot.json': json_10, '-P-O4GSfVGTkI16zJRVa4.snapshot.json': json_11 -} +} \ No newline at end of file diff --git a/packages/frontend/workspace/src/impl/cloud/blob.ts b/packages/frontend/workspace/src/impl/cloud/blob.ts index 119a8c008b..c7cde8a153 100644 --- a/packages/frontend/workspace/src/impl/cloud/blob.ts +++ b/packages/frontend/workspace/src/impl/cloud/blob.ts @@ -2,6 +2,7 @@ import { checkBlobSizesQuery, deleteBlobMutation, fetchWithTraceReport, + getBaseUrl, listBlobsQuery, setBlobMutation, } from '@affine/graphql'; @@ -10,14 +11,6 @@ import { fetcher } from '@affine/graphql'; import type { BlobStorage } from '../../engine/blob'; import { bufferToBlob } from '../../utils/buffer-to-blob'; -function getBaseUrl(): string { - if (environment.isDesktop) { - return runtimeConfig.serverUrlPrefix; - } - const { protocol, hostname, port } = window.location; - return `${protocol}//${hostname}${port ? `:${port}` : ''}`; -} - export const createAffineCloudBlobStorage = ( workspaceId: string ): BlobStorage => {