Skip to content

Commit

Permalink
added custom graphiqlfetcher logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tam33 committed Aug 15, 2024
1 parent 98a4666 commit 1469083
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions playground/src/components/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'graphiql/graphiql.css';
import '@graphiql/plugin-explorer/dist/style.css';
import '@/theme.css';

const graphiQLFetch = async (
const defaultGraphiQLFetch = async (
schema: GraphQLSchema | null,
clientValidationEnabled: boolean,
onFetch: any,
Expand Down Expand Up @@ -181,6 +181,13 @@ 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>;
}) => {
const url = input.routingUrl || import.meta.env.VITE_ROUTING_URL || '{{graphqlURL}}';

Expand Down Expand Up @@ -265,11 +272,17 @@ 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);
} else {
createFetcher = (...args) => input.customFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit);
}

return createGraphiQLFetcher({
url: url,
subscriptionUrl: window.location.protocol.replace('http', 'ws') + '//' + window.location.host + url,
fetch: (...args) =>
graphiQLFetch(schema, clientValidationEnabled, onFetch, args[0] as URL, args[1] as RequestInit),
fetch: createFetcher,
});
}, [schema, clientValidationEnabled]);

Expand Down

0 comments on commit 1469083

Please sign in to comment.