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

Commit 2673ddf

Browse files
committed
Use partials in page fragment
1 parent f9c26ca commit 2673ddf

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

api/wordpress/pages/queryPageById.js

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
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+
16
const {gql} = require('@apollo/client')
27

8+
// Fragment: retrieve single page fields.
9+
const singlePageFragment = gql`
10+
fragment SinglePageFields on Page {
11+
${globalPostFields}
12+
blocksJSON
13+
excerpt
14+
${seoPostFields}
15+
${authorPostFields}
16+
${featuredImagePostFields}
17+
}
18+
`
19+
320
// Query: retrieve page by specified identifier.
421
const queryPageById = gql`
5-
query GET_PAGE_BY_SLUG($id: ID!, $idType: PageIdType = URI) {
22+
query GET_PAGE_BY_SLUG(
23+
$id: ID!
24+
$idType: PageIdType = URI
25+
$imageSize: MediaItemSizeEnum = LARGE
26+
) {
627
page(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-
author {
24-
node {
25-
slug
26-
nickname
27-
}
28-
}
29-
featuredImage {
30-
node {
31-
altText
32-
sourceUrl(size: LARGE)
33-
}
34-
}
28+
...SinglePageFields
3529
}
3630
}
31+
${singlePageFragment}
3732
`
3833

3934
export default queryPageById

0 commit comments

Comments
 (0)