knoxpo / dart_algolia

[Unofficial] Algolia is a pure dart SDK, wrapped around Algolia REST API for easy implementation for your Flutter or Dart projects.
Other
117 stars 112 forks source link

Type 'List<String>' is not a subtype of type 'String' in `AlgoliaMultiIndexesReference` #115

Open SebastianWaloszek opened 1 year ago

SebastianWaloszek commented 1 year ago

Dart version: 2.18.6 Flutter version: 3.3.10 (stable)

Describe the bug When one sets a list of facet filters for a query to be performed as part of getObjects() inside AlgoliaMultiIndexesReference there's an encoding error being thrown.

dart:core                                        new _Uri
package:algolia/src/index_reference.dart 358:23  AlgoliaMultiIndexesReference._encodeMap
package:algolia/src/index_reference.dart 391:19  AlgoliaMultiIndexesReference.getObjects
test/algolia_test.dart 158:43                    main.<fn>.<fn>

type 'List<String>' is not a subtype of type 'String'

It only happens for AlgoliaMultiIndexesReference. When we try doing the same for AlgoliaIndexReference it works without issues.

To Reproduce One can reproduce the issue in tests by adding a list of facet filters:

      queryA = queryA.facetFilter([
        'email:johan.1@example.com',
        'email:johan.2@example.com',
      ]);

in the Perform Multiple Queries test like this:

    test('Perform Multiple Queries', () async {
      var queryA = algolia.instance.index('contacts').query('john');
      var queryB = algolia.instance.index('contacts_alt').query('jo');

      // Perform multiple facetFilters
      queryA = queryA.facetFilter('status:published');
      queryA = queryA.facetFilter('isDelete:false');
      queryA = queryA.facetFilter([
        'email:johan.1@example.com',
        'email:johan.2@example.com',
      ]);

      try {
        // Get Result/Objects
        var snap = await algolia.multipleQueries
            .addQueries([queryA, queryB]).getObjects();
        // Checking if has [List<AlgoliaQuerySnapshot>]
        expect(snap.length, 2);
        print('Queries count: ${snap.length}');
      } on AlgoliaError catch (err) {
        print(err.error.toString());
        expect(err.runtimeType, AlgoliaError);
      }
      print('\n\n');
    });

Expected behavior Encoding error should not happen inside AlgoliaMultiIndexesReference when the set facet filter for a query is a List<String>.

SebastianWaloszek commented 1 year ago

I have proposed a solution to this issue in this PR: https://github.com/knoxpo/dart_algolia/pull/116

jeremyKos commented 5 months ago

The problem still exist. Can you guy's add his PR ?