From 75b60a845e2687744f93cce57a69f57c0dc2b305 Mon Sep 17 00:00:00 2001 From: Hangzhi Yu <hangzhi@protonmail.com> Date: Fri, 5 May 2023 19:28:17 +0200 Subject: [PATCH] Enable gql batch queying --- CHANGELOG.rst | 1 + aleksis/core/frontend/app/apollo.js | 8 ++++++-- aleksis/core/settings.py | 1 + aleksis/core/urls.py | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 13a7f30ed..1d1501bfa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -34,6 +34,7 @@ Added * Provide API endpoint for system status. * [Dev] UpdateIndicator Vue Component to display the status of interactive pages * [Dev] DeleteDialog Vue Component to unify item deletion in the new frontend +* Use build-in mechanism in Apollo for GraphQL batch querying. Changed diff --git a/aleksis/core/frontend/app/apollo.js b/aleksis/core/frontend/app/apollo.js index 267997b9f..519bc24aa 100644 --- a/aleksis/core/frontend/app/apollo.js +++ b/aleksis/core/frontend/app/apollo.js @@ -2,11 +2,12 @@ * Configuration for Apollo provider, client, and caches. */ -import { ApolloClient, HttpLink, from } from "@/apollo-boost"; +import { ApolloClient, from } from "@/apollo-boost"; import { RetryLink } from "@/apollo-link-retry"; import { persistCache, LocalStorageWrapper } from "@/apollo3-cache-persist"; import { InMemoryCache } from "@/apollo-cache-inmemory"; +import { BatchHttpLink } from "@/apollo-link-batch-http"; // Cache for GraphQL query results in memory and persistent across sessions const cache = new InMemoryCache(); @@ -33,14 +34,17 @@ const links = [ // Automatically retry failed queries new RetryLink(), // Finally, the HTTP link to the real backend (Django) - new HttpLink({ + new BatchHttpLink({ uri: getGraphqlURL(), + batchInterval: 200, + batchDebounce: true, }), ]; /** Upstream Apollo GraphQL client */ const apolloClient = new ApolloClient({ cache, + shouldBatch: true, link: from(links), }); diff --git a/aleksis/core/settings.py b/aleksis/core/settings.py index bf6f4ffde..656fcd30a 100644 --- a/aleksis/core/settings.py +++ b/aleksis/core/settings.py @@ -587,6 +587,7 @@ YARN_INSTALLED_APPS = [ "@iconify/json@^2.1.30", "@mdi/font@^7.2.96", "apollo-boost@^0.4.9", + "apollo-link-batch-http@^1.2.14", "apollo-link-retry@^2.2.16", "apollo3-cache-persist@^0.14.1", "deepmerge@^4.2.2", diff --git a/aleksis/core/urls.py b/aleksis/core/urls.py index cc5d95452..7a22c7bb2 100644 --- a/aleksis/core/urls.py +++ b/aleksis/core/urls.py @@ -27,7 +27,7 @@ urlpatterns = [ path("__icons__/", include("dj_iconify.urls")), path( "graphql/", - csrf_exempt(views.LoggingGraphQLView.as_view(graphiql=True)), + csrf_exempt(views.LoggingGraphQLView.as_view(batch=True)), name="graphql", ), path("logo", force_maintenance_mode_off(views.LogoView.as_view()), name="logo"), -- GitLab