Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't make search query work in Sanity CMS

I am trying to perform a very basic search query with Sanity CMS. This is how the person schema I've created looks like:

export default {
  title: "Person",
  name: "person",
  type: "document",
  fields: [
    {
      title: "Name",
      name: "name",
      type: "string",
    }
  ]
}

I have entered two different Person data. And this is how I try to fetch the data:

const client = sanityClient({
  projectId: 'siaj5ql4',
  dataset: 'production',
  useCdn: true
})

const query = '*[_type == "person"]'

client.fetch(query).then(person => {
  console.log(person)
})

But I get an empty array like so in the console: [] There is no error or anything. Any ideas on this simple task?

like image 755
user1449456 Avatar asked Jul 31 '18 09:07

user1449456


People also ask

What is sanity CMS used for?

In this article, we will use Sanity CMS as our data repository. Sanity treats content like data and offers a concise number of features to manage images ( Image Pipeline ), text ( Portable Text ), and design, all with the goal of taking a structured approach to content that improves web app performance.

How can developers use sanity CMS with Gatsby?

Developers can use Sanity CMS with Gatsby to decrease build time and optimize web performance through a programmable modern platform that treats content like data. LogRocket is a frontend application monitoring solution that lets you replay problems as if they happened in your own browser.

How do I connect to sanity and retrieve data?

A way that tells Next how to connect to Sanity and retrieve data. We do this with one of the additional dependencies we installed. Create a file called sanityClient.js in the root of your Next project (ideally in a lib or utils folder) and add this to it: Your projectId can be found in the sanity.json file in your Sanity project directory.

What is sanity and how does it work?

Like Commerce.js, Sanity.io is a headless provider. Sanity makes it easy to customise structured content, tailor it for a given format, and display it on any front-end. This includes custom input fields and different kinds of pages templates.


1 Answers

There are two common reasons for this:

  1. The dataset is private and the client is not configured with a token.
  2. The documents you expect to see is not published (drafts are private by default) and the client is not configured with a token.

Also note that the CDN can not be used with private datasets and/or access token.

like image 148
bjoerge Avatar answered Sep 30 '22 06:09

bjoerge