From 07582e34c81c1f286a442cdeb4dee1e36cee8203 Mon Sep 17 00:00:00 2001 From: Adrian Smijulj Date: Mon, 23 Sep 2024 09:09:25 +0200 Subject: [PATCH] fix: patch GraphQL Playground's tooltips issue (#4272) --- .../src/plugins/Playground.tsx | 15 +++++++++++---- .../src/plugins/constants.ts | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 packages/app-graphql-playground/src/plugins/constants.ts diff --git a/packages/app-graphql-playground/src/plugins/Playground.tsx b/packages/app-graphql-playground/src/plugins/Playground.tsx index b863541ffb9..725a968d98e 100644 --- a/packages/app-graphql-playground/src/plugins/Playground.tsx +++ b/packages/app-graphql-playground/src/plugins/Playground.tsx @@ -17,6 +17,7 @@ import { config as appConfig } from "@webiny/app/config"; import ApolloClient from "apollo-client"; import { GraphQLPlaygroundTabPlugin } from "~/types"; import { SecurityIdentity } from "@webiny/app-security/types"; +import { ORIGINAL_GQL_PLAYGROUND_URL, PATCHED_GQL_PLAYGROUND_URL } from "./constants"; const withHeaders = (link: ApolloLink, headers: Record): ApolloLink => { return ApolloLink.from([ @@ -39,16 +40,20 @@ const initScripts = () => { return resolve(); } - return loadScript( - "https://cdn.jsdelivr.net/npm/@apollographql/graphql-playground-react@1.7.32/build/static/js/middleware.js", - resolve - ); + loadScript(PATCHED_GQL_PLAYGROUND_URL, (err: Error) => { + if (err) { + return loadScript(ORIGINAL_GQL_PLAYGROUND_URL, resolve); + } + + resolve(); + }); }); }; interface CreateApolloClientParams { uri: string; } + interface PlaygroundProps { createApolloClient: (params: CreateApolloClientParams) => ApolloClient; } @@ -57,9 +62,11 @@ interface CreateApolloLinkCallableParams { endpoint: string; headers: Record; } + interface CreateApolloLinkCallableResult { link: ApolloLink; } + interface CreateApolloLinkCallable { (params: CreateApolloLinkCallableParams): CreateApolloLinkCallableResult; } diff --git a/packages/app-graphql-playground/src/plugins/constants.ts b/packages/app-graphql-playground/src/plugins/constants.ts new file mode 100644 index 00000000000..9a3a5508b92 --- /dev/null +++ b/packages/app-graphql-playground/src/plugins/constants.ts @@ -0,0 +1,5 @@ +export const ORIGINAL_GQL_PLAYGROUND_URL = + "https://cdn.jsdelivr.net/npm/@apollographql/graphql-playground-react@1.7.32/build/static/js/middleware.js"; + +export const PATCHED_GQL_PLAYGROUND_URL = + "https://webiny-public.s3.us-east-2.amazonaws.com/project-scripts/gql-playground-mw-1.7.42-patched.js";