-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue where we get 'Unable to resolve image' if the user does not… #18
base: main
Are you sure you want to change the base?
Conversation
… select a default post image.
I noticed a similar thing for UPDATE: I think if we just make it required in the schema it'll at least, ahem, require it from the CMS: Added in 696ccd1 |
… gets to client and user understands it is required.
@@ -41,6 +41,7 @@ export default { | |||
name: 'publishedAt', | |||
title: 'Published at', | |||
type: 'datetime', | |||
validation: Rule => Rule.required(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based this off of the initialValue
templates docs: https://www.sanity.io/docs/initial-value-templates#dec5ffddbcc2 which shows how to prefill such fields
When I played in the GROQ playground it seems that "it likes" the ellipsis to be at the beginning. These examples on their docs site do that though I didn't find it mentioned that it's a requirement but I guess so. Note that we're getting some author data: I took liberty to add the other author properties since it's now coming back. |
@@ -1,7 +1,7 @@ | |||
import { useSanityClient } from "astro-sanity"; | |||
|
|||
export async function getAllPosts() { | |||
const query = `*[_type == 'post']{"categoryData": categories[]->{slug, title},author -> {name}, ...} | order(publishedAt desc)`; | |||
const query = `*[_type == 'post']{..., "categoryData": categories[]->{slug, title}, author->{name, slug, image, bio}} | order(publishedAt desc)`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides moving the ...
I remove extra spaces as I noted the examples on their docs don't have spaces and also you don't in the arrow for categories[]->{slug, title}
for example so it overall seemed the right thing to do ;-)
This fixes an issues I encountered first stab at getting up and running:
null
is working fine as the fallback there. Also, I noticed that everywhere else in the code we're using conditional rendering with{post.mainImage &&
... so this feels pretty consistent with that ;-)publishedDate
and validation required