Composables
Posts
Generated composables to fetch Posts and their content
WPNuxt provides 3 GraphQL queries to fetch posts (src):
#import "~/.queries/fragments/Post.fragment.gql"
query Posts($limit: Int = 10) {
posts(first: $limit) {
nodes {
...Post
}
}
}
query PostByUri($uri: String!) {
nodeByUri(uri: $uri) {
...Post
}
}
query PostById($id: ID!, $asPreview: Boolean = false) {
post(id: $id, idType: DATABASE_ID, asPreview: $asPreview) {
...Post
}
}
Which result in these generated PostFragment type and 3 composables:
import type { PostFragment } from '#graphql-operations'
const { data: allPosts } = await useWPPosts()
const { data: latestPosts } = await useWPPosts({ limit: 3 })
const { data: post1 } = await useWPPostByUri({ uri: 'slug' })
const { data: post2 } = await useWPPostById({ id: 'databaseId' })