diff --git a/src/graphql/base.ts b/src/graphql/base.ts index 2ad064e4..e8d8b896 100644 --- a/src/graphql/base.ts +++ b/src/graphql/base.ts @@ -41,16 +41,18 @@ export async function httpQuery({ method = "GET", json, headers = {}, + basePath = `/graphql`, }: { path?: string; method: string; json: unknown; headers: Recordable; + basePath?: string; }) { const timeoutId = setTimeout(() => { abortRequestsAndUpdate(); }, Timeout); - const url = `${BasePath}${path}`; + const url = `${basePath || BasePath}${path}`; const response: Response = await fetch(url, { method, headers: { diff --git a/src/graphql/http.ts b/src/graphql/http.ts new file mode 100644 index 00000000..63dcab3b --- /dev/null +++ b/src/graphql/http.ts @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { httpQuery } from "./base"; + +export default async function fetchQuery({ + headers, + method, + json, +}: { + method: string; + json: unknown; + headers: Recordable; +}) { + const response = await httpQuery({ + method, + json, + headers, + }); + if (response.errors) { + response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); + } + return response; +}