Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gatsby-source-reddit with all npm packages installed. Try it out:

require("gatsby/package.json"); // gatsby is a peer dependency. var gatsbySourceReddit = require("gatsby-source-reddit")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gatsby-source-reddit v0.3.0

Gatsby source for reddit

gatsby-source-reddit npm npm

Source plugin for pulling data into Gatsby from Reddit API

Usage

NPM

Package available here

Available parameters

  • username : user for who you want to query data
  • subredditName : subreddit for which you want to query data

If neither is provided, then an empty node with a random ID is passed back

gatsby-config.js

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-reddit`,
    options: {
      username:`gallowboob`
    }
  },
]

or

plugins: [
  {
    resolve: `gatsby-source-reddit`,
    options: {
      subreddit:`pics`
    }
  },
]

GraphQL queries

fragment UserDetails on RedditUser {
  fullnameId
  username
  created
  createdISO
  linkKarma
  commentKarma
}

fragment CommentDetails on RedditComment {
  author {
    ...UserDetails
  }
  body
}

query user {
  reddit {
    user(username: "aristotle") {
      ...UserDetails
    }
  }
}

query subreddit {
  reddit {
    subreddit(name: "dataisbeautiful") {
      name
      fullnameId
      title
      publicDescription
      accountsActive
      subscribers
      created
      createdISO
      hotListings {
        title
        fullnameId
        score
        numComments
        url
        author {
          ...UserDetails
        }
        comments {
          ...CommentDetails
        }
      }
      newListings {
        title
        fullnameId
        score
        numComments
        url
        author {
          ...UserDetails
        }
        comments {
          ...CommentDetails
        }
      }
      risingListings {
        title
        fullnameId
        score
        numComments
        url
        author {
          ...UserDetails
        }
        comments {
          ...CommentDetails
        }
      }
      controversialListings {
        title
        fullnameId
        score
        numComments
        url
        author {
          ...UserDetails
        }
        comments {
          ...CommentDetails
        }
      }
      topListings {
        title
        fullnameId
        score
        numComments
        url
        author {
          ...UserDetails
        }
        comments {
          ...CommentDetails
        }
      }
    }
  }
}

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free