@Test public void testSearchCategories() throws Exception { String query = getResource("graphql-queries/category-search.txt"); Utils.setupHttpResponse("magento-graphql-category-search.json", httpClient, HttpStatus.SC_OK, query); List<CategoryTree> categories = dataService.searchCategories("1.2.3.4.5", null, 0, 3, null); assertEquals(2, categories.size()); }
@Override public List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView) { if (categoryId == null) { LOGGER.debug("Performing category search with '{}' (page: {}, size: {})", text, currentPage, pageSize); } else { LOGGER.debug("Performing category search with '{}' in category {} (page: {}, size: {})", text, categoryId, currentPage, pageSize); } FilterMatchTypeInput name = new FilterMatchTypeInput().setMatch(text); CategoryFilterInput filters = new CategoryFilterInput().setName(name); QueryQuery.CategoryListArgumentsDefinition searchArgs = q -> q.filters(filters); CategoryTreeQueryDefinition queryArgs = q -> GraphqlQueries.CATEGORY_SEARCH_QUERY.apply(q); String queryString = Operations.query(query -> query.categoryList(searchArgs, queryArgs)).toString(); GraphqlResponse<Query, Error> response = execute(queryString, storeView); Query query = response.getData(); List<CategoryTree> categoryList = query.getCategoryList(); return categoryList; }
GraphqlDataServiceImpl implements GraphqlDataService { @Override public List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView) { if (categoryId == null) { LOGGER.debug("Performing category search with '{}' (page: {}, size: {})", text, currentPage, pageSize); } else { LOGGER.debug("Performing category search with '{}' in category {} (page: {}, size: {})", text, categoryId, currentPage, pageSize); } FilterMatchTypeInput name = new FilterMatchTypeInput().setMatch(text); CategoryFilterInput filters = new CategoryFilterInput().setName(name); QueryQuery.CategoryListArgumentsDefinition searchArgs = q -> q.filters(filters); CategoryTreeQueryDefinition queryArgs = q -> GraphqlQueries.CATEGORY_SEARCH_QUERY.apply(q); String queryString = Operations.query(query -> query.categoryList(searchArgs, queryArgs)).toString(); GraphqlResponse<Query, Error> response = execute(queryString, storeView); Query query = response.getData(); List<CategoryTree> categoryList = query.getCategoryList(); return categoryList; } }
GraphqlDataServiceImpl implements GraphqlDataService { @Override public List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView) { if (categoryId == null) { LOGGER.debug("Performing category search with '{}' (page: {}, size: {})", text, currentPage, pageSize); } else { LOGGER.debug("Performing category search with '{}' in category {} (page: {}, size: {})", text, categoryId, currentPage, pageSize); } FilterMatchTypeInput name = new FilterMatchTypeInput().setMatch(text); CategoryFilterInput filters = new CategoryFilterInput().setName(name); QueryQuery.CategoryListArgumentsDefinition searchArgs = q -> q.filters(filters); CategoryTreeQueryDefinition queryArgs = q -> GraphqlQueries.CATEGORY_SEARCH_QUERY.apply(q); String queryString = Operations.query(query -> query.categoryList(searchArgs, queryArgs)).toString(); GraphqlResponse<Query, Error> response = execute(queryString, storeView); Query query = response.getData(); List<CategoryTree> categoryList = query.getCategoryList(); return categoryList; }  }
GraphqlDataServiceImpl implements GraphqlDataService { @Override public List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView) { if (categoryId == null) { LOGGER.debug("Performing category search with '{}' (page: {}, size: {})", text, currentPage, pageSize); } else { LOGGER.debug("Performing category search with '{}' in category {} (page: {}, size: {})", text, categoryId, currentPage, pageSize); } FilterMatchTypeInput name = new FilterMatchTypeInput().setMatch(text); CategoryFilterInput filters = new CategoryFilterInput().setName(name); QueryQuery.CategoryListArgumentsDefinition searchArgs = q -> q.filters(filters); CategoryTreeQueryDefinition queryArgs = q -> GraphqlQueries.CATEGORY_SEARCH_QUERY.apply(q); String queryString = Operations.query(query -> query.categoryList(searchArgs, queryArgs)).toString(); GraphqlResponse<Query, Error> response = execute(queryString, storeView); Query query = response.getData(); List<CategoryTree> categoryList = query.getCategoryList(); return categoryList; }  @Activate void activate(GraphqlDataServiceConfiguration conf); @Override ProductInterface getProductBySku(String sku, String storeView); @Override CategoryTree getCategoryById(Integer id, String storeView); @Override CategoryTree getCategoryByPath(String urlPath, String storeView); @Override List<ProductInterface> searchProducts(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override CategoryProducts getCategoryProducts(Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override String getIdentifier(); }
GraphqlDataServiceImpl implements GraphqlDataService { @Override public List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView) { if (categoryId == null) { LOGGER.debug("Performing category search with '{}' (page: {}, size: {})", text, currentPage, pageSize); } else { LOGGER.debug("Performing category search with '{}' in category {} (page: {}, size: {})", text, categoryId, currentPage, pageSize); } FilterMatchTypeInput name = new FilterMatchTypeInput().setMatch(text); CategoryFilterInput filters = new CategoryFilterInput().setName(name); QueryQuery.CategoryListArgumentsDefinition searchArgs = q -> q.filters(filters); CategoryTreeQueryDefinition queryArgs = q -> GraphqlQueries.CATEGORY_SEARCH_QUERY.apply(q); String queryString = Operations.query(query -> query.categoryList(searchArgs, queryArgs)).toString(); GraphqlResponse<Query, Error> response = execute(queryString, storeView); Query query = response.getData(); List<CategoryTree> categoryList = query.getCategoryList(); return categoryList; }  @Activate void activate(GraphqlDataServiceConfiguration conf); @Override ProductInterface getProductBySku(String sku, String storeView); @Override CategoryTree getCategoryById(Integer id, String storeView); @Override CategoryTree getCategoryByPath(String urlPath, String storeView); @Override List<ProductInterface> searchProducts(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override List<CategoryTree> searchCategories(String text, Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override CategoryProducts getCategoryProducts(Integer categoryId, Integer currentPage, Integer pageSize, String storeView); @Override String getIdentifier();  }