Last active
December 22, 2020 22:50
-
-
Save gdhardy1/f88d3a78cc82c0fbf00915b190ced357 to your computer and use it in GitHub Desktop.
Gatsby Retry GraphQL Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Composing Apollo links | |
// https://www.apollographql.com/docs/link/composition/ | |
// for apollo-retry-link info: | |
// - https://www.apollographql.com/docs/link/links/retry/ | |
// - https://www.youtube.com/watch?v=bv74TcKb1jw | |
// for gatsby-source-grapql config info: | |
// see https://www.gatsbyjs.com/plugins/gatsby-source-graphql/ | |
// gatsby-config.js | |
// Creating Apollo Retry Link | |
const { createHttpLink, ApolloLink } = require("@apollo/client") | |
const { RetryLink } = require("@apollo/client/link/retry") | |
const retryLink = new RetryLink({ | |
delay: { | |
initial: 300, | |
max: Infinity, | |
jitter: true, | |
}, | |
attempts: { | |
max: 5, | |
retryIf: (error, _operation) => !!error, | |
}, | |
}); | |
module.exports = { | |
plugins: [ | |
{ | |
resolve: "gatsby-source-graphql", | |
options: { | |
typeName: "GitHub", | |
fieldName: "github", | |
url:"https://api.mysite.com/graphql", | |
// Create Apollo Link manually. Can return a Promise. | |
createLink: (pluginOptions) => { | |
return ApolloLink.from([retryLink, createHttpLink(pluginOptions)]); | |
}, | |
}, | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be done in
gatsby-config.js
. Must install@apollo/client
using your package manager.