Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 69f5951

Browse files
committed
Use partials in post fragment
1 parent e76d056 commit 69f5951

File tree

1 file changed

+27
-45
lines changed

1 file changed

+27
-45
lines changed

api/wordpress/posts/queryPostById.js

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,37 @@
1+
import globalPostFields from '../_partials/globalPostFields'
2+
import seoPostFields from '../_partials/seoPostFields'
3+
import authorPostFields from '../_partials/authorPostFields'
4+
import featuredImagePostFields from '../_partials/featuredImagePostFields'
5+
import tagsPostFields from '../_partials/tagsPostFields'
6+
import categoriesPostFields from '../_partials/categoriesPostFields'
7+
18
const {gql} = require('@apollo/client')
29

10+
// Fragment: retrieve single page fields.
11+
const singlePostFragment = gql`
12+
fragment SinglePostFields on Post {
13+
${globalPostFields}
14+
blocksJSON
15+
excerpt
16+
${seoPostFields}
17+
${authorPostFields}
18+
${featuredImagePostFields}
19+
${tagsPostFields}
20+
${categoriesPostFields}
21+
}
22+
`
323
// Query: retrieve post by specified identifier.
424
const queryPostById = gql`
5-
query GET_POST_BY_SLUG($id: ID!, $idType: PostIdType = SLUG) {
25+
query GET_POST_BY_SLUG(
26+
$id: ID!
27+
$idType: PostIdType = SLUG
28+
$imageSize: MediaItemSizeEnum = LARGE
29+
) {
630
post(id: $id, idType: $idType) {
7-
blocksJSON
8-
databaseId
9-
date
10-
slug
11-
title
12-
excerpt
13-
seo {
14-
canonical
15-
title
16-
metaDesc
17-
metaRobotsNofollow
18-
metaRobotsNoindex
19-
opengraphImage {
20-
sourceUrl
21-
}
22-
}
23-
tags {
24-
edges {
25-
node {
26-
name
27-
slug
28-
}
29-
}
30-
}
31-
author {
32-
node {
33-
slug
34-
nickname
35-
}
36-
}
37-
categories {
38-
edges {
39-
node {
40-
slug
41-
name
42-
}
43-
}
44-
}
45-
featuredImage {
46-
node {
47-
altText
48-
sourceUrl(size: LARGE)
49-
}
50-
}
31+
...SinglePostFields
5132
}
5233
}
34+
${singlePostFragment}
5335
`
5436

5537
export default queryPostById

0 commit comments

Comments
 (0)