-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
23,141 additions
and
39,168 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const defaultOptions = { | ||
// Arbitrary name for the remote schema Query type | ||
fieldName: `allBuilderModels`, | ||
typeName: `builder`, | ||
limit: 30, | ||
baseURL: `https://cdn.builder.io/api/v1/graphql`, | ||
overrideDev404: true, | ||
useCache: false, | ||
batch: true, | ||
// custom404Dev: 'path to custom 404' | ||
// globalContext: { store: process.env.STORE_TOKEN } // helpful in multi stores repo | ||
// filter: (entry) => entry.content.data.store === process.env.STORE_TOKEN // helpful in multi-store builder organization | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const { createHttpLink } = require(`apollo-link-http`) | ||
const { RetryLink } = require(`apollo-link-retry`) | ||
const { defaultOptions } = require('./constants'); | ||
const { ApolloLink } = require('apollo-link'); | ||
const invariant = require(`invariant`); | ||
|
||
const retryLink = new RetryLink({ | ||
delay: { | ||
initial: 100, | ||
max: 2000, | ||
jitter: true, | ||
}, | ||
attempts: { | ||
max: 5, | ||
retryIf: (error, operation) => | ||
Boolean(error) && ![400, 401, 403, 404].includes(error.statusCode), | ||
}, | ||
}) | ||
|
||
module.exports = (options) => { | ||
const config = { | ||
...defaultOptions, | ||
...options, | ||
} | ||
|
||
invariant( | ||
config.publicAPIKey && config.publicAPIKey.length > 0, | ||
`@builder.io/gatsby requires a public API Key` | ||
); | ||
|
||
invariant( | ||
config.limit < 101, | ||
'@builder.io/gatsby maximum pagination limit is 100' | ||
); | ||
|
||
const graphqlOptions = { | ||
typeName: config.typeName, | ||
// Field under which the remote schema will be accessible. You'll use this in your Gatsby query | ||
fieldName: config.fieldName, | ||
// Url to query from 30 | ||
url: `${config.baseURL}/${config.publicAPIKey}?${!config.useCache ? "cachebust=true" : ''}`, | ||
batch: config.batch, | ||
createLink: pluginOptions => ApolloLink.from([ | ||
retryLink, | ||
createHttpLink({ uri: pluginOptions.url }), | ||
]), | ||
}; | ||
|
||
return { | ||
plugins: [ | ||
{ | ||
resolve: 'gatsby-source-graphql', | ||
options: graphqlOptions, | ||
} | ||
] | ||
} | ||
}; |
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
This file was deleted.
Oops, something went wrong.