kbrock84 / gatsby-source-fetch Goto Github PK
View Code? Open in Web Editor NEWA simple Gatsbyjs plugin for fetching things using axios
License: MIT License
A simple Gatsbyjs plugin for fetching things using axios
License: MIT License
The current implementation only sends one request and does not check for failure.
Update gatsby-node.js to implement a retry
and better handle errors when the request is not successful.
Users should be able to configure the retry attempts and configure timeout lengths, but there should be acceptable defaults:
module.exports = {
plugins: [
// fetch data from some endpoint and load it into graphql
{
resolve: `gatsby-source-fetch`,
options: {
name: `footer`,
type: `html`,
url: `https://www.some-domain.com/common-html/header.html`,
retry: {
times: 4,
// possibly some form of configuring timeouts?
timeout: [ 100, 2000, 30000, 30000 ],
// or just
timeout: 2000
}
}
}
]
}
Thanks for this plugin, it's great.
Is there any way to use the url option of the source plugin as a function? I believe that Gatsby allows for this.
I don't know the url ahead of time because it's on a CDN and it changes on every update.
Right now I have:
{
resolve: `gatsby-source-fetch`,
options: {
name: `brands`,
type: `brands`,
url: `https://a-fixed-url.com`,
method: `get`,
axiosConfig: {
headers: { Accept: "text/csv" },
},
saveTo: `${__dirname}/src/data/file.csv`,
createNodes: false,
},
}
But could it be something like:
{
resolve: `gatsby-source-fetch`,
options: {
name: `brands`,
type: `brands`,
url: async () => {
// Some async request...
const url = await requestToApi()
return url,
},
method: `get`,
axiosConfig: {
headers: { Accept: "text/csv" },
},
saveTo: `${__dirname}/src/data/file.csv`,
createNodes: false,
},
}
I'm not sure this is possible at all?
Many thanks for your help.
EDIT: I just created a local version for my project and implemented this feature. Would you be open to a PR for this? If so, I'll submit one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.