Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collectionSlug for SearchInput #405

Closed
oncode opened this issue Jul 7, 2020 · 1 comment
Closed

Add collectionSlug for SearchInput #405

oncode opened this issue Jul 7, 2020 · 1 comment
Milestone

Comments

@oncode
Copy link
Contributor

oncode commented Jul 7, 2020

Is your feature request related to a problem? Please describe.
Collections can currently be fetched with id or slug in the collection query. It would also be nice to be able to search the products with a slug in the search query. With this, the collection and product search data could be fetched with the same request.

Describe the solution you'd like

query MyDreamCollectionRouteQuery($collectionSlug: String!) {
  collection(slug: $collectionSlug) {
    id
    name
  }
  search(
    input: {
      groupByProduct: true
      collectionSlug: $collectionSlug
    }
  ) {
    ...ProductFields
  }
}

Describe alternatives you've considered
Executing the collection query first to get the ID and then the search query, but this would increase the loading time and require two requests. Currently I have a file that maps the slugs to their IDs.

@michaelbromley
Copy link
Member

I agree this would be a nice addition to the API.

In terms of implementation we have 2 options:

  1. In the resolver, check to see if the collectionSlug field is truthy. If so, query the Collection id based on the slug, then use the id in the same way it already works.
    Pro: No changes need to indexing
    Con: An additional DB query needed when using the slug to search.
  2. Index the slug as part of the search index.
    Pro: No additional query needed, better perf at search time.
    Con: Need to index the slug in each supported language. Need listen for CollectionModificationEvent and update search index items when the slug changes.

Actually we already listen for CollectionModificationEvent so the second option would probably be preferable, also since the runtime performance will be better - searches are performed orders of magnitude more often than collection updates. In that case it would be a schema change for the DefaulSearchPlugin and therefore a breaking change - next minor release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants