fix: use absolute path in gql client (#5454) (#5462)

This commit is contained in:
DarkSky
2023-12-29 16:02:29 +08:00
committed by GitHub
parent de951c8779
commit 9e94e7195b
3 changed files with 15 additions and 11 deletions
+12 -1
View File
@@ -2,4 +2,15 @@ export * from './fetcher';
export * from './graphql';
export * from './schema';
export * from './utils';
import '@affine/env/global';
import { setupGlobal } from '@affine/env/global';
setupGlobal();
export function getBaseUrl(): string {
if (environment.isDesktop) {
return runtimeConfig.serverUrlPrefix;
}
const { protocol, hostname, port } = window.location;
return `${protocol}//${hostname}${port ? `:${port}` : ''}`;
}
@@ -7,7 +7,7 @@ import type {
QueryVariables,
RecursiveMaybeFields,
} from '@affine/graphql';
import { gqlFetcherFactory } from '@affine/graphql';
import { getBaseUrl, gqlFetcherFactory } from '@affine/graphql';
import type { GraphQLError } from 'graphql';
import { useCallback, useMemo } from 'react';
import type { Key, SWRConfiguration, SWRResponse } from 'swr';
@@ -22,7 +22,7 @@ import useSWRMutation from 'swr/mutation';
setupGlobal();
export const fetcher = gqlFetcherFactory('/graphql');
export const fetcher = gqlFetcherFactory(getBaseUrl() + '/graphql');
/**
* A `useSWR` wrapper for sending graphql queries
@@ -2,6 +2,7 @@ import {
checkBlobSizesQuery,
deleteBlobMutation,
fetchWithTraceReport,
getBaseUrl,
listBlobsQuery,
setBlobMutation,
} from '@affine/graphql';
@@ -10,14 +11,6 @@ import { fetcher } from '../../affine/gql';
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 => {