Is it possible to call two queries at the same time, even if one query is the helper getByUID with SvelteKit's load function? I am trying to call all of my doc types in my blog post which I am calling the data with the UID helper, but I need to pass all the blog-type data into another component. I don't see much documentation about calling multiple queries except with multiple predicates. Here is what i tried below and the result i received was posts: [at(document.type, "blog_post")]
<script context="module">
import Prismic from "@prismicio/client";
import PrismicDom from "prismic-dom";
import Client from "../../../utils/client";
export async function load({ page }) {
const { uid } = page.params;
const document = await Client.getByUID("blog_post", uid);
const posts = await Prismic.Predicates.at("document.type", "blog_post");
if (document) {
return {
props: {
document,
uid,
posts,
},
};
} else {
return {
status: 404,
error: "Post not found",
};
}
}
</script>
<script>
export let document;
export let posts;
console.log("posts:", posts);
const post = document.data;
</script>
It seems to return an object of the type of document versus all of the documents posts: [at(document.type, "blog_post")]. document itself returns the post data which i am iterating through successfully.
I am confused because I am using the same exact query in our blog index as shown below which works
A colleague just pointed out to me that you are missing wrap the predicate with the client, just like you're doing in the 'blog index'. It should look like this:
<script context="module">
import Prismic from "@prismicio/client";
import PrismicDom from "prismic-dom";
import Client from "../../../utils/client";
export async function load({ page }) {
const { uid } = page.params;
const document = await Client.getByUID("blog_post", uid);
const posts = await Client.query(
Prismic.Predicates.at("document.type", "blog_post")
);
if (document) {
return {
props: {
document,
uid,
posts,
},
};
} else {
return {
status: 404,
error: "Post not found",
};
}
}
</script>
<script>
export let document;
export let posts;
console.log("posts:", posts);
const post = document.data;
</script>