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

AdvancedSearch: ExternalIndex Search Error #23

Open
ramon-sg opened this issue Jul 6, 2023 · 0 comments
Open

AdvancedSearch: ExternalIndex Search Error #23

ramon-sg opened this issue Jul 6, 2023 · 0 comments

Comments

@ramon-sg
Copy link

ramon-sg commented Jul 6, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant