Giter VIP home page Giter VIP logo

gatsby-source-contentstack's Introduction

gatsby-source-contentstack

Contentstack provides a source plugin for pulling content into Gatsby from Contentstack stacks. It helps you query content types and entries in Gatsby using GraphQL.

Here’s an example site built using this source plugin: https://xenodochial-hodgkin-8a267e.netlify.com/

Install

npm install --save gatsby-source-contentstack

How to use

Open the gatsby-config.js file from the root directory of your Gatsby project and configure it with below parameters

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-contentstack`,
    options: {
      // Required: API Key is a unique key assigned to each stack.
      api_key: `api_key`,

      // Required: Delivery Token is a read-only credential. 
      delivery_token: `delivery_token`,
      
      // Required: Environment where you published your data.
      environment: `environment`,

      // Optional: CDN set this to point to other cdn end point. For eg: https://eu-cdn.contentstack.com/v3 
      cdn: `cdn_url`,

      // Optional: expediteBuild set this to either true or false
      expediteBuild: `boolean_value`,

      // Optional: Specify true if you want to generate custom schema
      enableSchemaGeneration : `boolean_value`,

      // Optional: Specify a different prefix for types. This is useful in cases where you have multiple instances of the plugin to be connected to different stacks.
      type_prefix: `Contentstack`, // (default)
    },
  },
]
// Note: access_token has been replaced by delivery_token

There is a provision to speed up the gatsby build process. To do this, you can set the value of the expediteBuild to true. So when you set the value of this parameter to true, the build process is significantly enhanced as only published assets and entries are synced parallelly.

However, when you want to perform gatsby develop, ensure to set the value of expediteBuild to false.

How to query

You can query nodes created from Contentstack using GraphQL.

All content types and the corresponding entries are pulled from your stack. They'll be created in your site's GraphQL schema under contentstack${contentTypeID} and allContentstack${contentTypeID}.

Note: Learn to use the GraphQL tool and Ctrl+Spacebar at http://localhost:8000/___graphql to discover the types and properties of your GraphQL model.

Querying entries

If, for example, you have Blogs as one of your content types, you will be able to query its entries in the following manner:

{
  allContentstackBlogs {
    edges {
      node {
        id
        title
        url
        description
        banner {
          filename
          url
        }
        created_at
      }
    }
  }
}

Query Reference fields

Reference fields provide references to entries of another content type(s). Since fields from referred entry is often needed, the referred entry data is provided at the reference field.

{
  allContentstackBlogs{
    edges {
      node {
        id
        title
        url
        description
        authors{
          name
        }
        created_at
      }
    }
  }
}

Coming soon

  • Asset type and Image processing support using gatsby-transformer-sharp, gatsby-plugin-sharp.

gatsby-source-contentstack's People

Contributors

asmit-patil avatar harshalpatel91 avatar andrejpavlovic avatar hiteshbal91 avatar jacobimpson avatar

Watchers

James Cloos avatar

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.