Giter Club home page Giter Club logo

gatsby-source-fetch's People

Contributors

kbrock84 avatar michaelpumo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

michaelpumo

gatsby-source-fetch's Issues

Implement Retry for Axios Fetch

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
                              }
                       }
                }
       ]
}

URL as a function

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.