This unofficial source plugin makes Optimizely/Episerver API data available in GatsbyJS sites. Currently in active development.
This plugin @epicdesignlabs/gatsby-source-optimizely is no longer maintained and now officially deprecated. Please use this unofficial, but currently maintained gatsby-source-optimizely plugin instead as Im still currently maintaining this plugin.
Provide support for the following features:
- Multiple
optimizely/episerverAPI versions - Multiple, additional custom headers
- Custom request timeout in all
optimizely/episerverAPI requests - Data caching on subsequent
gatsbysource plugin runs - Request timeouts in all
optimizely/episerverAPI requests - Throttling, debouncing, and adjusting the number of concurrent
optimizely/episerverAPI requests - Add support for
expandeddata on some content blocks:images,dynamicStyles,items,form,image1,imagekey fields are currently supported with more to come in the future - Option for opting out of type inference for
optimizely/episerverAPIgatsbynodes or add customgatsbynode schemas foroptimizely/episerverAPIgatsbynodes
For npm:
npm install gatsby-source-optimizelyFor yarn:
yarn add gatsby-source-optimizelySetup this plugin in gatsby-config.js as follows (*required fields):
module.exports = { // ... plugins: [ // ... { resolve: "gatsby-source-optimizely", options: { auth: { site_url: process.env.OPTMIZELY_API_SITE_URL // The URL of the Optimizely/Episerver API site, username: process.env.OPTMIZELY_API_USERNAME // The username of the Optimizely/Episerver API user., password: process.env.OPTMIZELY_API_PASSWORD // The password of the Optimizely/Episerver API user., grant_type: process.env.OPTMIZELY_API_GRANT_TYPE, // // The grant type of the Optimizely/Episerver API user. Default is "password" client_id: process.env.OPTMIZELY_API_CLIENT_ID, // The client ID of the Optimizely/Episerver API user. Default is "Default" }, endpoints: [ { nodeName: "OptimizelyPageContent", endpoint: "/api/episerver/v2.0/content?references=14099,14104,14105,14106,14107,14109,14111,14110,14112,16621,14118,14117,14119,14980&expand=*", schema: null }, { nodeName: "OptimizelyHomePageContentChildren", endpoint: "/api/episerver/v2.0/content/14099/children?expand=*", schema: null }, { nodeName: "OptimizelyLocations", endpoint: "/api/locations?lang=en-us&market=US", schema: ` id: ID! images: [String] inRiverId: Int! latitude: String sharpenImages: [File] @link(from: "fields.localFile") ` } ] }, }, ], };Add additional headers to the request as follows:
options: { // ... auth: { headers: { // Single header "X-Custom-Header": "Custom Value", // Mutiple headers "Access-Control-Allow-Headers": "Custom Value", "Access-Control-Allow-Credentials": "Custom Value", "Access-Control-Allow-Origin": "Custom Value", "Access-Control-Allow-Methods": "Custom Value" } } }Add a single or multiple endpoints.
Note: The
endpointsshould start with/api/**/*as the base URL will be added automatically to youroptions.auth.site_urlvalue.
options: { // ... endpoints: [ // Single endpoint { nodeName: "OptimizelyPageContent", endpoint: "/api/episerver/v2.0/content?references=14099,14104,14105,14106,14107,14109,14111,14110,14112,16621,14118,14117,14119,14980&expand=*", schema: null }, // Multiple endpoints { nodeName: "OptimizelyHomePageContentChildren", endpoint: "/api/episerver/v2.0/content/14099/children?expand=*", schema: null }, { nodeName: "OptimizelyLocations", endpoint: "/api/locations?lang=en-us&market=US", schema: ` type OptimizelyLocations implements Node { id: ID! images: [String] inRiverId: Int! latitude: String sharpenImages: [File] @link(from: "fields.localFile") } ` } ]; }Add a global schema to all endpoints. This will be merged with the endpoint schema. This is useful for adding global types that affect multiple endpoints.
options: { // ... globals: { schema: ` type ContentLink { id: Int! url: String! } ` }, endpoints: [ { nodeName: "OptimizelyPageContent", endpoint: "/api/episerver/v2.0/content?references=14099,14104,14105,14106,14107,14109,14111,14110,14112,16621,14118,14117,14119,14980&expand=*", schema: ` id: ID! name: String metaTitle: String metaDescription: String contentLink: ContentLink ` } ] }Set a custom request timeout for the Optimizely/Episerver API requests (in milliseconds).
Default: 0 (0 second).
options: { // ... request_timeout: 0; }Set a custom request throttling interval for the Optimizely/Episerver API requests (in milliseconds).
Default: 0 (0 second).
options: { // ... request_throttle_interval: 0; }Set a custom request debouncing interval for the Optimizely/Episerver API requests (in milliseconds).
Default: 0 (0 seconds).
options: { // ... request_debounce_interval: 0; }Set a custom request concurrency for the Optimizely/Episerver API requests.
Default: 10000.
options: { // ... request_concurrency: 10000; }Assuming you correctly setup the plugin in gatsby-config.js and you have a OptimizelyContent node name and its valid endpoint:
options: { // ... globals: { schema: ` type ContentLink { id: Int! url: String! } ` }, endpoints: [ { nodeName: "OptimizelyPageContent", endpoint: "/api/episerver/v2.0/content?references=14099,14104,14105,14106,14107,14109,14111,14110,14112,16621,14118,14117,14119,14980&expand=*", schema: ` type OptimizelyPageContent implements Node { id: ID! name: String metaTitle: String metaDescription: String contentLink: ContentLink } ` } ] }you can query the data as follows:
{ allOptimizelyPageContent { edges { node { id name metaTitle metaDescription contentLink { id url } } } } }Please feel free to contribute! PRs are always welcome.
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.