diff --git a/src/graphql/base.ts b/src/graphql/base.ts index e8d8b896..7a2d33dc 100644 --- a/src/graphql/base.ts +++ b/src/graphql/base.ts @@ -34,25 +34,23 @@ class HTTPError extends Error { } } -const BasePath = `/graphql`; +export const BasePath = `/graphql`; export async function httpQuery({ - path = "", + url = "", method = "GET", json, headers = {}, - basePath = `/graphql`, }: { - path?: string; method: string; json: unknown; - headers: Recordable; - basePath?: string; + headers?: Recordable; + url: string; }) { const timeoutId = setTimeout(() => { abortRequestsAndUpdate(); }, Timeout); - const url = `${basePath || BasePath}${path}`; + const response: Response = await fetch(url, { method, headers: { diff --git a/src/graphql/custom-query.ts b/src/graphql/custom-query.ts index c53badf2..376dcf6d 100644 --- a/src/graphql/custom-query.ts +++ b/src/graphql/custom-query.ts @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { httpQuery } from "./base"; +import { httpQuery, BasePath } from "./base"; async function customQuery(param: { queryStr: string; conditions: { [key: string]: unknown } }) { const response = await httpQuery({ + url: BasePath, method: "post", json: { query: param.queryStr, variables: { ...param.conditions } }, - headers: {}, }); if (response.errors) { response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); diff --git a/src/graphql/http.ts b/src/graphql/http/index.ts similarity index 84% rename from src/graphql/http.ts rename to src/graphql/http/index.ts index 63dcab3b..99fc976d 100644 --- a/src/graphql/http.ts +++ b/src/graphql/http/index.ts @@ -14,21 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { httpQuery } from "./base"; +import { httpQuery } from "../base"; -export default async function fetchQuery({ - headers, - method, - json, -}: { - method: string; - json: unknown; - headers: Recordable; -}) { +export default async function fetchQuery({ method, json, url }: { method: string; json: unknown; url: string }) { const response = await httpQuery({ method, json, - headers, + url, }); if (response.errors) { response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); diff --git a/src/graphql/http/url.ts b/src/graphql/http/url.ts new file mode 100644 index 00000000..199995ff --- /dev/null +++ b/src/graphql/http/url.ts @@ -0,0 +1,21 @@ +/** + * 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. + */ +export const ClusterNodes = `/status/cluster/nodes`; + +export const ConfigTTL = `/status/config/ttl`; + +export const DebuggingConfigDump = `/debugging/config/dump`; diff --git a/src/graphql/index.ts b/src/graphql/index.ts index 435118d6..9c72887c 100644 --- a/src/graphql/index.ts +++ b/src/graphql/index.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { httpQuery } from "./base"; +import { httpQuery, BasePath } from "./base"; import * as app from "./query/app"; import * as selector from "./query/selector"; import * as dashboard from "./query/dashboard"; @@ -50,8 +50,8 @@ class Graphql { } async params(variables: unknown) { const response = await httpQuery({ + url: BasePath, method: "post", - headers: {}, json: { query: query[this.queryData], variables, diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 12e139e6..e3a26549 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -47,6 +47,10 @@ limitations under the License. --> {{ t("timeReload") }} +