GROQ
language is used to query the sanity data based on the query string. The query string in GROQ describes exactly what information you need from the Sanity server. Later in the course, we use the GROQ query in the React component to fetch the data from the Sanity Server.
In the Sanity Studio, we can download a vision plugin to practice GROQ queries. Vision is a plugin that lets you quickly test your GROQ queries right from the Studio. You can learn more about Vision plugin on the below page.
To install the @sanity/vision
plugin, we need to install the below command in the terminal:
sanity install @sanity/vision
To add sanity vision in the project, we can write the below line of code in the /schemas/schema.js
file.
To practice the GROQ you can navigate to the below route in Sanity Studio.
Next, we can write the GROQ query to fetch the customer data as below:
In the above image, we use the GROQ query as below:
*[_type == 'customer' && email == 'example@example.com']{
_id,
name,
email,
password
}
In the upcoming section, we'll GROQ query to fetch the data from the Sanity server and practice writing the GROQ query.