diff --git a/src/core/dbc-gateway/graphql-fetcher.ts b/src/core/dbc-gateway/graphql-fetcher.ts index b016bc9d67..167f41e766 100644 --- a/src/core/dbc-gateway/graphql-fetcher.ts +++ b/src/core/dbc-gateway/graphql-fetcher.ts @@ -1,17 +1,16 @@ -import { QueryFunctionContext } from "react-query"; import FetchFailedCriticalError from "../fetchers/FetchFailedCriticalError"; import { getToken, TOKEN_LIBRARY_KEY, TOKEN_USER_KEY } from "../token"; +import { + getServiceBaseUrl, + serviceUrlKeys +} from "../utils/reduxMiddleware/extractServiceBaseUrls"; import DbcGateWayHttpError from "./DbcGateWayHttpError"; -import { getQueryUrlFromContext } from "./helper"; export const fetcher = ( query: string, variables?: TVariables ) => { - return (context?: QueryFunctionContext): Promise => { - // Resolve the url based on the query name if present. - const url = getQueryUrlFromContext(context); - + return (): Promise => { // The whole concept of agency id, profile and and bearer token needs to be refined. // First version is with a library token. const token = getToken(TOKEN_USER_KEY) || getToken(TOKEN_LIBRARY_KEY); @@ -23,7 +22,7 @@ export const fetcher = ( ? ({ Authorization: `Bearer ${token}` } as object) : {}; - return fetch(url, { + return fetch(getServiceBaseUrl(serviceUrlKeys.fbi), { method: "POST", ...{ headers: { diff --git a/src/core/dbc-gateway/helper.ts b/src/core/dbc-gateway/helper.ts deleted file mode 100644 index 1abb846ad8..0000000000 --- a/src/core/dbc-gateway/helper.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { QueryFunctionContext } from "react-query"; -import { - getServiceBaseUrl, - serviceUrlKeys -} from "../utils/reduxMiddleware/extractServiceBaseUrls"; - -const map = { - searchWithPagination: serviceUrlKeys.fbiSearch, - getMaterial: serviceUrlKeys.fbiMaterial, - default: serviceUrlKeys.fbi -} as const; - -const resolveBaseUrl = (query: string | null) => { - if (!query) { - return getServiceBaseUrl(map.default); - } - return getServiceBaseUrl(map[query as keyof typeof map] || map.default); -}; - -export const getQueryUrlFromContext = ( - context: QueryFunctionContext | undefined -) => { - // Get the default base url if no context. - if (!context) { - return resolveBaseUrl(null); - } - - const { queryKey } = context; - const [queryName] = queryKey; - return resolveBaseUrl(queryName as string); -}; - -export default {}; diff --git a/src/core/storybook/serviceUrlArgs.ts b/src/core/storybook/serviceUrlArgs.ts index a481c8ebfc..be76c11f76 100644 --- a/src/core/storybook/serviceUrlArgs.ts +++ b/src/core/storybook/serviceUrlArgs.ts @@ -31,15 +31,5 @@ export default { name: "Base url for the FBI API", defaultValue: "https://fbi-api.dbc.dk/next/graphql", control: { type: "text" } - }, - [serviceUrlKeys.fbiSearch]: { - name: "Base url for the FBI API (search)", - defaultValue: "https://fbi-api.dbc.dk/next/graphql", - control: { type: "text" } - }, - [serviceUrlKeys.fbiMaterial]: { - name: "Base url for the FBI API (material)", - defaultValue: "https://fbi-api.dbc.dk/next/graphql", - control: { type: "text" } } }; diff --git a/src/core/utils/reduxMiddleware/extractServiceBaseUrls.ts b/src/core/utils/reduxMiddleware/extractServiceBaseUrls.ts index 2969c5c83b..03b1b96fb7 100644 --- a/src/core/utils/reduxMiddleware/extractServiceBaseUrls.ts +++ b/src/core/utils/reduxMiddleware/extractServiceBaseUrls.ts @@ -1,35 +1,21 @@ import { EnhancedStore } from "@reduxjs/toolkit"; import { Middleware } from "redux"; -type Api = - | "publizon" - | "fbs" - | "dplCms" - | "cover" - | "materialList" - | "fbi" - | "fbiSearch" - | "fbiMaterial"; - +type Api = "publizon" | "fbs" | "dplCms" | "cover" | "materialList" | "fbi"; export type ApiBaseUrlKey = `${Api}BaseUrl`; -export type ServiceBaseUrls = - | Record - | Record; - -type ServiceBaseUrlKey = keyof ServiceBaseUrls; - export const serviceUrlKeys: Record = { fbs: "fbsBaseUrl", publizon: "publizonBaseUrl", dplCms: "dplCmsBaseUrl", cover: "coverBaseUrl", materialList: "materialListBaseUrl", - fbi: "fbiBaseUrl", - fbiSearch: "fbiSearchBaseUrl", - fbiMaterial: "fbiMaterialBaseUrl" + fbi: "fbiBaseUrl" } as const; +type ServiceBaseUrls = Record | Record; +type ServiceBaseUrlKey = keyof typeof serviceBaseUrls; + // ServiceBaseUrls "store". We use this to store the base urls for the different services. let serviceBaseUrls: ServiceBaseUrls = {}; diff --git a/src/core/utils/types/global-url-props.ts b/src/core/utils/types/global-url-props.ts index 791c001f97..ca5ece4086 100644 --- a/src/core/utils/types/global-url-props.ts +++ b/src/core/utils/types/global-url-props.ts @@ -10,8 +10,6 @@ interface GlobalUrlEntryPropsInterface { coverBaseUrl: string; materialBaseUrl: string; fbiBaseUrl: string; - fbiSearchBaseUrl: string; - fbiMaterialBaseUrl: string; authUrl: string; ereolenHomepageUrl: string; }