Anyone have any experience with graphql react and ...
# prisma-whats-new
a
Anyone have any experience with graphql react and instant search algolia? I am currently trying to implement instant search but i notice that the docs use Hits to display the data which only allows you to access the ids individually.. so if i were to requery for more properties from graph cool I would need to call a query individually maybe… idk is this the best way has anyone tackled this before? Thanks in advance! 🙂
By this i mean trying to get more data from the objects you get back from instant search.. by somehow getting the ids back in a list instead of through the hit callback as an individual id!
would adding those properties onto the index make the search super expensive?
the proper way is to use a query to get the properties for every id right? i am just trying to see if there is a way to get a list of id's from instant search! 😄
n
hmm as far as I remember the id is already part of the index and should be included in the hits from instant search
here you see how we use the Hit component
it exposes a hit prop that should include the id
a
Thanks!! I guess what i am asking is i need to use the id to get more data about the entry... so should i be making an individual query for each hit like this?
Copy code
Const HitToQuery = ({hit}) => {
  console.log('Query begin');
  const queried = graphql(
    findBite, {
      variables: {
        id: hit.id
      }
    }
  )(QueryToBite);
  console.log(queried);
  return queried;
};`
where i pass that in
Copy code
<Hits hitComponent={HitToQuery}/>
or is there a better way to access more data bout an id after the search? 😄
n
ahh right. I was of the impression you can get the hits as an array as well. Maybe @dzello can help with obtaining the list of ids of the hits?
a
ooooh thanks!! Yea if there is a way that would be super sweet!! 😄
n
that being said, why do you want to prevent firing multiple queries?
a
hmm idk is it expensive? Also the above code doesnt run because we catch it while it's still loading the component and Hits doesn't render the loading component... would you know how to fix that?:)
Thanks so much again nilan!
n
could you try pulling the graphql wrapper out of the HitToQuery component? it would then receive a new prop "data" and you could check data.loading
let me know how that goes! heading out now ;)
a
Thanks!! will do!! I will try that 😄
d
I think your best bet will be to map the hits into a list of ids, maybe storing that in component state and firing a single query based on it. You can specify that you want only certain fields back at query time if you want the payload to be really light.
n
Thanks @dzello! The question is if this is possible using Algolia React Instantsearch. Seems like the
<Hits />
component handles the hits internally and doesn't grant access to the list of hits directly, is there a way to access them?
d
Yeah. The
hitComponent
property receives a
hit
prop will all the info in it. https://community.algolia.com/react-instantsearch/widgets/Hits.html
n
Yea so this gives us access to each hit individually by passing in a component. But how can we access all hits at once to collect the list of their ids?
d
n
ahh! That looks like exactly what we need. Thanks! I saw the connectors before but I thought it's about connecting to refinements
d
The connector API is slightly lower layer of abstraction, the default widgets are built on top of them.
Ah good feedback, yeah it’s not the easiest concept to grok right away
n
Awesome, I think that's enough information for @aaronkchsu to tinker around with this. 👍
a
Thanks so much team this helps immensely! ❤️