In queries object we have this transformer function, which, as you know, proves to be very helpful when it comes to preprocessing data that we want to send to Algolia side:
const queries = [
{
query: myQuery,
transformer: ({ data }) => data.allSitePage.edges.map(({ node }) => node), // optional
indexName: 'index name to target', // overrides main index name, optional
settings: {
// optional, any index settings
},
matchFields: ['slug', 'modified'], // Array<String> overrides main match fields, optional
},
];
In readme we can read, that transformer could be an async function, but in reality passing an async function breaks the code completely.
Consider this situation in which I had intention to additionally process some of the fields using 3rd party libs (though I abstracted everything to ease understanding):
I think this is a bug and a .map method should not be chained right away since there could be no mappable object at all, just like in the case above, where after evaluation we have something like:
const objects = await Promise<any>.map(...)
Which is the main cause of crashing.
If you could separate transform and map steps into 2, everything would work as expected:
Here is the fiddle with everything I've just tried to explain.
Please, let me know if I had misunderstood something and a bug actually hides in my code or if I should provide more information related to this issue.
In
queries
object we have thistransformer
function, which, as you know, proves to be very helpful when it comes to preprocessing data that we want to send to Algolia side:In readme we can read, that
transformer
could be an async function, but in reality passing an async function breaks the code completely.Consider this situation in which I had intention to additionally process some of the fields using 3rd party libs (though I abstracted everything to ease understanding):
This lead to this error:
If we proceed to the source code, here is exactly the place where it breaks:
I think this is a bug and a
.map
method should not be chained right away since there could be no mappable object at all, just like in the case above, where after evaluation we have something like:Which is the main cause of crashing.
If you could separate transform and map steps into 2, everything would work as expected:
Here is the fiddle with everything I've just tried to explain.
Please, let me know if I had misunderstood something and a bug actually hides in my code or if I should provide more information related to this issue.