From e9a1afe7bf1711a2d5a9628f2a24e6bab601aaad Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Thu, 30 Nov 2023 15:15:11 +0300 Subject: [PATCH] Do not call split on every request (#3122) --- packages/graphql-yoga/src/plugins/use-graphiql.ts | 6 +++--- packages/graphql-yoga/src/plugins/use-unhandled-route.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/graphql-yoga/src/plugins/use-graphiql.ts b/packages/graphql-yoga/src/plugins/use-graphiql.ts index 3e4eba59b..99653a817 100644 --- a/packages/graphql-yoga/src/plugins/use-graphiql.ts +++ b/packages/graphql-yoga/src/plugins/use-graphiql.ts @@ -98,12 +98,12 @@ export function useGraphiQL>( }; return { async onRequest({ request, serverContext, fetchAPI, endResponse, url }) { - const requestedUrl = request.url.split('?')[0]; if ( shouldRenderGraphiQL(request) && - (requestedUrl.endsWith(config.graphqlEndpoint) || - requestedUrl.endsWith(`${config.graphqlEndpoint}/`) || + (request.url.endsWith(config.graphqlEndpoint) || + request.url.endsWith(`${config.graphqlEndpoint}/`) || url.pathname === config.graphqlEndpoint || + url.pathname === `${config.graphqlEndpoint}/` || getUrlPattern(fetchAPI).test(url)) ) { logger.debug(`Rendering GraphiQL`); diff --git a/packages/graphql-yoga/src/plugins/use-unhandled-route.ts b/packages/graphql-yoga/src/plugins/use-unhandled-route.ts index 89a074f0f..9d4ad44e6 100644 --- a/packages/graphql-yoga/src/plugins/use-unhandled-route.ts +++ b/packages/graphql-yoga/src/plugins/use-unhandled-route.ts @@ -15,11 +15,11 @@ export function useUnhandledRoute(args: { } return { onRequest({ request, fetchAPI, endResponse, url }) { - const requestedUrl = request.url.split('?')[0]; if ( - !requestedUrl.endsWith(args.graphqlEndpoint) && - !requestedUrl.endsWith(`${args.graphqlEndpoint}/`) && + !request.url.endsWith(args.graphqlEndpoint) && + !request.url.endsWith(`${args.graphqlEndpoint}/`) && url.pathname !== args.graphqlEndpoint && + url.pathname !== `${args.graphqlEndpoint}/` && !getUrlPattern(fetchAPI).test(url) ) { if (