From f7949c990900aac0aec3d46654c57f6e80eb349b Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 6 Sep 2024 10:37:10 -0700 Subject: [PATCH] Don't introspect schema on interval --- src-web/hooks/useIntrospectGraphQL.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src-web/hooks/useIntrospectGraphQL.ts b/src-web/hooks/useIntrospectGraphQL.ts index f23d5a41..99f3c60e 100644 --- a/src-web/hooks/useIntrospectGraphQL.ts +++ b/src-web/hooks/useIntrospectGraphQL.ts @@ -1,6 +1,6 @@ import type { HttpRequest } from '@yaakapp/api'; 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 { minPromiseMillis } from '../lib/minPromiseMillis'; import { getResponseBodyText } from '../lib/responseBody'; @@ -29,8 +29,6 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) { namespace: 'global', }); - const introspectionInterval = useRef(); - useEffect(() => { const fetchIntrospection = async () => { setIsLoading(true); @@ -63,16 +61,9 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) { await setIntrospection(data); }; - const runIntrospection = () => { - fetchIntrospection() - .catch((e) => setError(e.message)) - .finally(() => setIsLoading(false)); - }; - - // Do it again on an interval - clearInterval(introspectionInterval.current); - introspectionInterval.current = setInterval(runIntrospection, 1000 * 60); - runIntrospection(); // Run immediately + fetchIntrospection() + .catch((e) => setError(e.message)) + .finally(() => setIsLoading(false)); // eslint-disable-next-line react-hooks/exhaustive-deps }, [request.id, request.url, request.method, refetchKey, activeEnvironment?.id]);