-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(gatsby-cms-plugin): fetch content by ID using REST API from CMS for preview #1120
Conversation
✔️ Deploy Preview for faststoreui ready! 🔨 Explore the source changes: 40fa516 🔍 Inspect the deploy log: https://app.netlify.com/sites/faststoreui/deploys/61ef19c278ee8b000763bb3d 😎 Browse the preview: https://deploy-preview-1120--faststoreui.netlify.app |
✔️ Deploy Preview for faststore ready! 🔨 Explore the source changes: 40fa516 🔍 Inspect the deploy log: https://app.netlify.com/sites/faststore/deploys/61ef19c21e74d50008de552b 😎 Browse the preview: https://deploy-preview-1120--faststore.netlify.app |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 40fa516:
|
|
||
console.error(await response.text()) | ||
|
||
throw new Error(`Error while fetching ${input}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest putting this code inside an if branch and removing the response.json() from the branch. Response returning "ok" is the "happy path," so put it as most left as possible.
fetchAllRemoteNodes(gatsbyApi, options), | ||
fetchAllLocalNodes(gatsbyApi), | ||
]).then(([x, y]) => [...x, ...y].filter(Boolean)) | ||
const { webhookBody }: any = gatsbyApi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this object be typed with a better type, can't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can type it, but we can't guarantee the user passing this params, by default it's an open object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right. But at least could type something like interface Interface { webhookBody?: any }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @mateuspontes. I don't have enough context about this plugin, but the code makes sense. I left some suggestions that aren't required. Did you test this code in some store repo? If yes, can you share?!
19d91b3
to
40fa516
Compare
What's the purpose of this pull request?
This PR enables gatsby-plugin-cms to receive
webhookBody
params, fetch the values on the CMS API and return it to preview on webOps.How does it work?
REST API example: https://storecomponents.myvtex.com/_v/cms/api/faststore/home/72de3769-347e-4734-855a-e5a4f072f66b?versionId=e2f4f2c0-9001-4f6b-b318-35f50ae2e3fb
How to test it?
yarn develop
on this folder to build the files and start the server on your store usingENABLE_GATSBY_REFRESH_ENDPOINT=true
, you should see the home page from production.References
This PR was totally inspired by https://github.com/vtex/cms/pull/8 from @tlgimenes