mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 14:59:42 +02:00
Don't introspect schema on interval
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import type { HttpRequest } from '@yaakapp/api';
|
import type { HttpRequest } from '@yaakapp/api';
|
||||||
import type { IntrospectionQuery } from 'graphql';
|
import type { IntrospectionQuery } from 'graphql';
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { buildClientSchema, getIntrospectionQuery } from '../components/core/Editor';
|
import { buildClientSchema, getIntrospectionQuery } from '../components/core/Editor';
|
||||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||||
import { getResponseBodyText } from '../lib/responseBody';
|
import { getResponseBodyText } from '../lib/responseBody';
|
||||||
@@ -29,8 +29,6 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) {
|
|||||||
namespace: 'global',
|
namespace: 'global',
|
||||||
});
|
});
|
||||||
|
|
||||||
const introspectionInterval = useRef<NodeJS.Timeout>();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchIntrospection = async () => {
|
const fetchIntrospection = async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -63,16 +61,9 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) {
|
|||||||
await setIntrospection(data);
|
await setIntrospection(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const runIntrospection = () => {
|
fetchIntrospection()
|
||||||
fetchIntrospection()
|
.catch((e) => setError(e.message))
|
||||||
.catch((e) => setError(e.message))
|
.finally(() => setIsLoading(false));
|
||||||
.finally(() => setIsLoading(false));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Do it again on an interval
|
|
||||||
clearInterval(introspectionInterval.current);
|
|
||||||
introspectionInterval.current = setInterval(runIntrospection, 1000 * 60);
|
|
||||||
runIntrospection(); // Run immediately
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [request.id, request.url, request.method, refetchKey, activeEnvironment?.id]);
|
}, [request.id, request.url, request.method, refetchKey, activeEnvironment?.id]);
|
||||||
|
|||||||
Reference in New Issue
Block a user