update query

This commit is contained in:
Fine 2025-05-27 10:34:29 +08:00
parent c7a087e715
commit c38ba1c0b2
6 changed files with 37 additions and 22 deletions

View File

@ -34,25 +34,23 @@ class HTTPError extends Error {
} }
} }
const BasePath = `/graphql`; export const BasePath = `/graphql`;
export async function httpQuery({ export async function httpQuery({
path = "", url = "",
method = "GET", method = "GET",
json, json,
headers = {}, headers = {},
basePath = `/graphql`,
}: { }: {
path?: string;
method: string; method: string;
json: unknown; json: unknown;
headers: Recordable; headers?: Recordable;
basePath?: string; url: string;
}) { }) {
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
abortRequestsAndUpdate(); abortRequestsAndUpdate();
}, Timeout); }, Timeout);
const url = `${basePath || BasePath}${path}`;
const response: Response = await fetch(url, { const response: Response = await fetch(url, {
method, method,
headers: { headers: {

View File

@ -14,13 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { httpQuery } from "./base"; import { httpQuery, BasePath } from "./base";
async function customQuery(param: { queryStr: string; conditions: { [key: string]: unknown } }) { async function customQuery(param: { queryStr: string; conditions: { [key: string]: unknown } }) {
const response = await httpQuery({ const response = await httpQuery({
url: BasePath,
method: "post", method: "post",
json: { query: param.queryStr, variables: { ...param.conditions } }, json: { query: param.queryStr, variables: { ...param.conditions } },
headers: {},
}); });
if (response.errors) { if (response.errors) {
response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); response.errors = response.errors.map((e: { message: string }) => e.message).join(" ");

View File

@ -14,21 +14,13 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { httpQuery } from "./base"; import { httpQuery } from "../base";
export default async function fetchQuery({ export default async function fetchQuery({ method, json, url }: { method: string; json: unknown; url: string }) {
headers,
method,
json,
}: {
method: string;
json: unknown;
headers: Recordable;
}) {
const response = await httpQuery({ const response = await httpQuery({
method, method,
json, json,
headers, url,
}); });
if (response.errors) { if (response.errors) {
response.errors = response.errors.map((e: { message: string }) => e.message).join(" "); response.errors = response.errors.map((e: { message: string }) => e.message).join(" ");

21
src/graphql/http/url.ts Normal file
View File

@ -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`;

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { httpQuery } from "./base"; import { httpQuery, BasePath } from "./base";
import * as app from "./query/app"; import * as app from "./query/app";
import * as selector from "./query/selector"; import * as selector from "./query/selector";
import * as dashboard from "./query/dashboard"; import * as dashboard from "./query/dashboard";
@ -50,8 +50,8 @@ class Graphql {
} }
async params(variables: unknown) { async params(variables: unknown) {
const response = await httpQuery({ const response = await httpQuery({
url: BasePath,
method: "post", method: "post",
headers: {},
json: { json: {
query: query[this.queryData], query: query[this.queryData],
variables, variables,

View File

@ -47,6 +47,10 @@ limitations under the License. -->
<i class="ml-10">{{ t("timeReload") }}</i> <i class="ml-10">{{ t("timeReload") }}</i>
</div> </div>
</div> </div>
<div class="flex-h item">
<span class="label">{{ t("TTL") }}</span>
<div> TTL </div>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>