1

I'm doing a code-along for a twitter clone and am not able to get tweets. I'm using Sanity and can confirm the data is there, and is fetched w/o error on sanity client. I think the issue is with groq, I've uninstalled, reinstalled it, installed it as a standalone, and I'm still getting an empty array when console logging. Any Ideas?

Here is the getTweets below

import { groq } from 'next-sanity'
import type { NextApiRequest, NextApiResponse } from 'next'
import { sanityClient } from '../../sanity'
import { Tweet } from '../../typings'


const feedQuery = groq`
*[_type =='tweet' && !blockTweet]{_id,...} | 
order(_createdAt desc)`


type Data = {
  tweets: Tweet[]
}

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse<Data>
) {
    const tweets: Tweet[] = await sanityClient.fetch(feedQuery);

  console.log(tweets)
  res.status(200).json({ tweets })
}

AntH00
  • 13
  • 4

1 Answers1

0

Do you have vision installed? You can run your query and see what comes back without relying on your frontend code. Sanity Vision

The work incrementally in vision trying:

*[_type =='tweet']

Then to see if your conditional is correct:

*[_type =='tweet' && !blockTweet]

Then add the data after in brackets

    *[_type =='tweet' && !blockTweet] {
_id,
...
}

Try this:

const feedQuery = groq`
*[_type == 'tweet']{
  _id,
  ...
}| order(_createdAt desc)`
Rob W
  • 16
  • 3
  • Thanks @Rob W, that worked. I do have vision and confirmed that work prior to trying your code. It looks like it's because of !blockTweet, that it wasn't parsing to the front-end. It works now. Thanks again. – AntH00 Aug 24 '22 at 04:06