Skip to content

Commit

Permalink
fixed type errors and added graphiqlfetchtype
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tam33 committed Aug 16, 2024
1 parent 73c12b7 commit 1013573
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
18 changes: 7 additions & 11 deletions playground/src/components/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TbDevicesCheck } from 'react-icons/tb';
import { cn } from '@/lib/utils';
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { GraphiQLFetchType } from './types';
import 'graphiql/graphiql.css';
import '@graphiql/plugin-explorer/dist/style.css';
import '@/theme.css';
Expand Down Expand Up @@ -181,13 +182,7 @@ export const Playground = (input: {
routingUrl?: string;
hideLogo?: boolean;
theme?: 'light' | 'dark' | undefined;
customFetch?: (
schema: GraphQLSchema | null,
clientValidationEnabled: boolean,
onFetch: any,
url: URL,
init: RequestInit,
) => Promise<Response>;
customGraphiQLFetch?: GraphiQLFetchType;
}) => {
const url = input.routingUrl || import.meta.env.VITE_ROUTING_URL || '{{graphqlURL}}';

Expand Down Expand Up @@ -272,11 +267,12 @@ export const Playground = (input: {
setResponse(JSON.stringify(response));
};

let createFetcher;
if (!input.customFetch) {
createFetcher = (...args) => defaultGraphiQLFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit);
let createFetcher : typeof fetch;
let customGraphiQLFetch = input.customGraphiQLFetch;
if (customGraphiQLFetch !== undefined) {
createFetcher = (...args: any[]) => customGraphiQLFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit);
} else {
createFetcher = (...args) => input.customFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit);
createFetcher = (...args : any[]) => defaultGraphiQLFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit);
}

return createGraphiQLFetcher({
Expand Down
10 changes: 10 additions & 0 deletions playground/src/components/playground/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GraphQLSchema } from 'graphql';

export type LoadStatsEntry = {
name: string;
durationSinceStart: string;
Expand Down Expand Up @@ -37,3 +39,11 @@ export type FetchNode = {
loadSkipped: boolean;
loadStats?: LoadStats;
};

export type GraphiQLFetchType = (
schema: GraphQLSchema | null,
clientValidationEnabled: boolean,
onFetch: any,
url: URL,
init: RequestInit,
) => Promise<Response>;

0 comments on commit 1013573

Please sign in to comment.