Above is an example of how you would perform the allCategory query operation. In this query, the fields _id and primaryImage are being requested.
Notice that primaryImage is followed by a set of {} with nested fields that are being requested. This is because primaryImage is neither a string, number, boolean, or null. It is a complex data type i.e an object therefore you must specify what fields are to be returned for that object
Queries that are ran in a gql playground can be copied exactly as is and injected into a fetch's body.query
The body of a gql fetch, must be stringified
GQL queries all use the POST method to execute
All gql response will contain a data wrapper around the requested query response, so when we convert the response to json, we can safetly destructure data from the response
Sanity
sanity graphql deploy allows you to create a gql endpoint for your sanity project
sanity login / sanity logout is how you authenticated to your sanity project in the terminal
08/19 Day 18 Lecture Notes
Review of Morning Exercise
GQL
allCategory
query operation. In this query, the fields_id
andprimaryImage
are being requested.primaryImage
is followed by a set of{}
with nested fields that are being requested. This is becauseprimaryImage
is neither astring
,number
,boolean
, ornull
. It is a complex data type i.e anobject
therefore you must specify what fields are to be returned for thatobject
Lecture
Fetching with GQL
fetch
'sbody.query
body
of a gql fetch, must be stringifiedPOST
method to executedata
wrapper around the requested query response, so when we convert the response tojson
, we can safetly destructuredata
from the responseSanity
sanity graphql deploy
allows you to create a gql endpoint for your sanity projectsanity login
/sanity logout
is how you authenticated to your sanity project in the terminal