To summerize first: I am wondering how to send the URL of the page back to Strapi from Gatsby so the user can see it in an uneditable field when he creates the page.
I am trying to figure out if it's possible to mutate the field in Strapi after the build of the page has been completed.
I am generating 50-60 landing pages which after they are done building get their own path.
For example:
https://test.com/newly-generated-page
What I want to do is I want to send that path back to Strapi every time the user creates a new page and assign it to that page in the database so the user can see it in the "Page Path" field.
So there will be something like this in Strapi:
Page Path: https://test.com/newly-generated-page
One of the options would be to do an Axios PUT request to that endpoing inside the React page template, but then that API will be called every time when the page renders.
Other option sounds better - to do it right after Gatsby has finished building that page.
Get a list of all the landing page paths with GQL (just like I did in the code below) and send back that information from Gatbsy to Strapi (that part isn't done).
I have tried implementing it through gatsby-node.js but I can't seem to find a solution for it.
I've tried something like this with Gatsby's onPostBuild API in gatsby-node.js, I have managed to get a list of all the paths but I am not really sure if this would be the right way of doing it:
exports.onPostBuild = ({ graphql }) => {
const getPagePaths = makeRequest(
graphql,
`
{
allSitePage {
nodes {
path
id
}
}
}
`
).then(result => {
result.data.allSitePage.nodes.forEach(({ path, id }) => {
console.log(path, id)
})
})
return Promise.all([
getPagePaths
])
}
So now after a postBuild API was called and all the gatsby pages are built, and I got a list of all the page PATHs - I need to send them back to Strapi with an API PUT request and assign it to Strapi field as I mentioned above.
Anyone with any idea for this?
2 options I guess - Axios PUT request or some sort of Mutation