How to get Prismic API to only return specific fields?

I'm currently loading all my blog posts on one page like so using getStaticProps.

const allPosts = await client.getAllByType("blog_post", {
		predicates: [prismic.predicate.not("my.blog_post.status", "9 - Promoted")],
		orderings: {
			field: "my.blog_post.published",
			direction: "desc",
		},
	})

This returns all the blog post data for all the content in every single post. Is there a way to get the API to only return a few specific fields? I only really a headline, image and the URL to the post. I don't need anything in the body content or repeated slices.

I'm getting a warning when I run my project:

Warning: data for page "/blog" is 3.83 MB, this amount of data can reduce performance.
See more info here: https://nextjs.org/docs/messages/large-page-data

Looking through the documentation I see ways to query by specific parameters but I don't see anything to get the API to return only certain fields. Wondering if this is possible or if I'm just not understanding the documentation.

To be clear I'm not trying to query by specific fields, I'm trying to query all blog posts and have the API return ONLY a few specific fields.

Thanks!

  • N

Hello @niki.brown

Thanks for reaching out to us.

You can use the fetch parameter to make queries to retrieve the specified fields.

Please find more details on how to format the fetch parameter:

Let me know if you have any questions.

Thanks,
Priyanka

Thank you! Will take a look.

I just used fetch to only request the fields I needed on my blog page and reduced the page size by 90%!!!! Thanks!

@niki.brown Great. Let us know if you have any questions.