Skip to content

Commit c40cc84

Browse files
committed
Speed up page build by using graphgql instead of doc query
The document interface is not that optimized as the graphql endpoint
1 parent db830e9 commit c40cc84

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/pages/[name].tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function Doc(
5252
) {
5353
let html = getHtml(props.entry)
5454
let displayElement = <div dangerouslySetInnerHTML={{ __html: html }} />
55-
if (typeof props.entry.document.body === "undefined") {
55+
if (props.entry.document.body === null) {
5656
displayElement = defaultDoc(props.entry.document, props.menu)
5757
}
5858
return (
@@ -89,31 +89,34 @@ export async function getStaticPaths() {
8989
}
9090

9191
export async function getStaticProps({ params }) {
92-
// Connect and configure the TerminusClient
93-
const client = new TerminusClient.WOQLClient(
94-
"https://cloud.terminusdb.com/TerminatorsX",
95-
{
96-
97-
organization: "TerminatorsX",
98-
db: "terminusCMS_docs",
99-
token: process.env.TERMINUSDB_API_TOKEN,
100-
}
101-
)
10292
const config = {
10393
headers: { Authorization: `Token ${process.env.TERMINUSDB_API_TOKEN}` },
10494
}
105-
const query = {
106-
"@type": "Page",
107-
slug: params["name"],
95+
const doc = await axios.post(
96+
"https://cloud.terminusdb.com/TerminatorsX/api/graphql/TerminatorsX/terminusCMS_docs",
97+
{
98+
query: `query {
99+
Page(filter: {slug: {eq: "${params['name']}"}}) {
100+
slug,
101+
title {
102+
value
103+
},
104+
body {
105+
value
106+
},
107+
seo_metadata {
108+
description,
109+
og_image,
110+
title
111+
}
108112
}
109-
const docs = await client.getDocument({
110-
"@type": "Page",
111-
as_list: true,
112-
query: query,
113-
})
114-
const docResult = docs[0]
113+
}`,
114+
},
115+
config
116+
)
117+
const docResult = doc.data.data.Page[0]
115118
let html = ""
116-
if (typeof docResult["body"] !== "undefined") {
119+
if (docResult["body"] !== null) {
117120
html = await renderMarkdown(docResult["body"]["value"])
118121
}
119122
const entry = { html: html, document: docResult }

0 commit comments

Comments
 (0)