Need help on filtering Categories based on category property

I want to filter some Categories based on its boolean ShowOnHomepage property, I have tested the query through the graphql-playground, it returns desired result (just returned the Categories have ShowOnHomepage of true):

{
categories(storeId: “B2B-store”,filter:“ShowOnHomePage:true category.subtree:25f5ea1b52e54ec1aa903d44cc889324”){
totalCount
items{
name
id
imgSrc
slug
}
}
}

But, in the implementation the filter does not take effect, it return all the Categories

function getCategoriesQueryDocument(): DocumentNode {
return gql query GetCategories( $storeId: String! $userId: String $cultureName: String $currencyCode: String ) { categories( storeId: $storeId userId: $userId cultureName: $cultureName currencyCode: $currencyCode ) { totalCount items{ name id imgSrc slug } };
}

export async function getCategories(payload: Omit<QueryCategoriesArgs, “storeId”>): Promise<Category> {
const { storeId, userId, cultureName, currencyCode } = globals;

const { data } = await graphqlClient.query<Required<Pick<Query, “categories”>>, QueryCategoriesArgs>({
query: getCategoriesQueryDocument(),
variables: {
storeId,
userId,
cultureName,
currencyCode,
…payload,
},
});

return data.categories.items ?? ;
}

Note that the playload has been filled with the expected filler string filter:“ShowOnHomePage:true category.subtree:25f5ea1b52e54ec1aa903d44cc889324”

How should I do/check from this to have expected result as through the graphql-playground?

Thanks,

All is correct from a high-level point of view. Which search provider do you use?

Could you Capture web session traffic - support - Virto Commerce and share with me?

1 Like

Thank @OlegoO for the quick reply!
It became a guide from your mention of web session traffic capturing: looking into the traffic data I see that the request to the GraphQL endpoint has not expected filter string.
The gpl string must be like this (to get expected result):

gql query GetCategories( $storeId: String! $userId: String $cultureName: String $currencyCode: String $filter: String ) { categories( storeId: $storeId userId: $userId cultureName: $cultureName currencyCode: $currencyCode filter: $filter ) {...};
}

Cause: the original gql had not its filter variable

1 Like