Hey all, let’s say I have content types ‘StandardPost’ and ‘ReviewPost’. They are identical except review post has the extra fields ‘rating’, ‘pros’ and ‘cons’. I want my...
Last updated: Nov 1, 2020
Hey all, let’s say I have content types ‘StandardPost’ and ‘ReviewPost’. They are identical except review post has the extra fields ‘rating’, ‘pros’ and ‘cons’. I want my Category pages to list and sort all posts, regardless of whether they are StandardPost or ReviewPost. Would the following GROQ query be valid and accomplish this? *[_type == “standardPost” || _type == “reviewPost”] | order(_createdAt desc)
If it does, that’d be awesome. AFAIK sorting wouldn’t be possible with GraphQL unless you wrap them in a ‘Post’ type which would reference reviewPost or standardPost (really messy).
Nov 1, 2020, 4:28 PM
It looks like it should. You can try out the query using Vision (
Nov 1, 2020, 4:30 PM
. I haven't actually started using Sanity (I'm considering it for this reason, actually). But from the GROQ.dev playground, it seems possible. However, I take it this would mean I'd have to stay away from Gatsby as that enforces the GraphQL API
Nov 1, 2020, 4:40 PM
I see. I decided on Sanity over a few others and have been very happy with it so far. I’ve never used this plugin personally as I haven’t built anything with Gatsby and Sanity, but this may be worth checking out: https://github.com/kmcaloon/gatsby-plugin-groq
Nov 1, 2020, 4:44 PM
Interesting. I prefer to stick with official libraries so I think I'll skip Gatsby, since I was already planning to try something on the new release of NextJS
Nov 1, 2020, 4:56 PM
Your query will work but you can simplify it like this