vendure-ecommerce/vendure-plus-issues

AdvancedSearch: ExternalIndex Search Error

Opened this issue · 0 comments

When I configure an external index (I have included the documentation example to illustrate), we get the error below. This also makes that the search in the admin doesn't work.

The error happens when the query_by param is string array instead of a string.

export const cmsExternalIndex = new ExternalIndex<CmsArticleDocument>({
//...
fields: {
    id: {
      type: 'string',
      facet: false,
    },
    title: {
      type: 'string',
      facet: false,
    },
    slug: {
      type: 'string',
      facet: false,
    },
    breadcrumb: {
      type: 'str)ing[]',
      facet: false,
    },
  },

  createTypesenseSearchParams: (ctx, injector, input) => {
    const per_page = input.take ?? 10;
    const page =
      input.skip && 0 < input?.skip
        ? Math.ceil(input.skip / per_page) + 1
        : undefined;
    return {
      q: input.term,
      query_by: ['breadcrumb'], // <---
      prefix: input.prefixMode ?? false,
      per_page,
      page,
    };
  },
//...
}
query {
  searchExternal(input: {indexes: ["cms-articles"], term: "Home"}) {
   
    ... on CmsArticlesResponse {
      items {
        id
        title
        
        highlights {
          matchedTokens
        }
      }
    }
  }
}
{
  "errors": [
    {
      "stack": "GraphQLError: String cannot represent value: [\"Home\"]\n    at GraphQLScalarType.serializeString [as serialize] (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/type/scalars.js:173:9)\n    at completeLeafValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:653:37)\n    at completeValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:578:12)\n    at completeValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:556:21)\n    at /Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:620:25\n    at Array.map (<anonymous>)\n    at safeArrayFrom (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/jsutils/safeArrayFrom.js:36:23)\n    at completeListValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:607:53)\n    at completeValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:572:12)\n    at completeValue (/Users/ramon/Projects/Cleanqueen/source/cleanqueen-api/node_modules/graphql/execution/execute.js:556:21)",
      "message": "String cannot represent value: [\"Home\"]",
      "name": "GraphQLError",
      "locations": [

Captura de pantalla 2023-07-06 a la(s) 13 37 11