vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.78k stars 1.03k forks source link

Harden plugin blocks simple query #3213

Open Huararanga opened 1 day ago

Huararanga commented 1 day ago

Hi vendure, harden plugin generates high complexity for simple query for my sitemap.

[HardenPlugin] Query complexity of "anonymous" is 4626, which exceeds the maximum of 650

"Rest of queries seems to be unaffected"

To Reproduce 1) Enable harden plugin import { HardenPlugin } from "@vendure/harden-plugin";

HardenPlugin.init({ maxQueryComplexity: 650, apiMode: process.env.APP_ENV === "dev" ? "dev" : "prod", }),

2) Add sitemap query:

import gql from 'graphql-tag'; import { sdk } from '../../graphqlWrapper'; import { CollectionListOptions, ProductListOptions } from '~/generated/graphql';

export function getSitemap( request: Request, collectionOptions?: CollectionListOptions, productOptions?: ProductListOptions, ) { return sdk .sitemap({ collectionOptions, productOptions }, { request }) .then((result) => ({ collections: result.collections?.items, products: result.products?.items, })); }

gql query sitemap($collectionOptions: CollectionListOptions, $productOptions: ProductListOptions) { collections(options: $collectionOptions) { items { slug updatedAt } } products(options: $productOptions) { items { slug updatedAt } } } ;

3) Execute the query import { getSitemap } from '~/providers/sitemap/sitemap'; const sitemapData = await getSitemap(request);

Expected behavior Its simple query. Harden plugin should detect low complexity. But generates complexity 4626

Environment (please complete the following information):

oidt commented 15 hours ago

With the option logComplexityScore on true you can get the exact reason for that score. Getting all the collections and all the products can be pretty intense so it looks like a simple query but can give large problems on large stores.