DomDew/strapi-plugin-fuzzy-search

Null result on GraphQL endpoint for collection names with more than one word

aadelgrossi opened this issue · 4 comments

Similar behavior described in issue #37

While attempting to register a new model in fuzzy search with uid such as api::app-user.app-user and modelName app-user, always returns null as a response, regardless if the query string is matched or not

Even if no results where to be found, the expected response would be data: []

Not working ❌

{
          uid: 'api::app-user.app-user',
          modelName: 'app-user',
          fuzzysortOptions: {
            characterLimit: 60,
            threshold: -100,
            limit: 20,
            keys: [
              {
                name: 'name',
                weight: 100,
              },
              {
                name: 'nickname',
                weight: 60,
              },
            ],
          },
        }, 

Response:

"data": {
    "search": {
      "appUsers": null
    }
  }

When querying a model that is named with a single word (no dashes autogenerated by strapi when creating the content type), the results are returned correctly (or with an empty array if no matches)

this works ✅

{
    uid: 'api::user.user',
    modelName: 'user',
    fuzzysortOptions: {
        characterLimit: 60,
        threshold: -100,
        limit: 20,
        keys: [{
                name: 'name',
                weight: 100,
            },

        ],
    },
},

Response:

{
  "data": {
    "search": {
      "users": {
        "data": [
          {
            "attributes": {
              "name": "myuser"
            }
          }
        ]
      }
    }
  }
}

This only happens when querying via GraphQL, querying through REST endpoint returns the array as expected:

http://localhost:1337/api/fuzzy-search/search?query=myuser

"app-users": [{
    "id": 1,
    "name: "myuser"
    "createdAt": "2023-01-26T14:57:48.151Z",
    "updatedAt": "2023-01-26T14:57:49.382Z",
    "publishedAt": "2023-01-26T14:57:49.375Z"
}],

Plugin versions
@strapi/strapi@4.4.5
strapi-plugin-fuzzy-search@^1.10.2

Hey @aadelgrossi ,
thanks for bringing this up!

Trying to fix this asap.

Wow, it was some serious finding of a needle in a haystack, but it should be fixed now in 1.10.3!

@all-contributors please add @aadelgrossi for bug

@DomDew thank you so much for taking the time and fixing this so quickly 😄🙏