gatsby-source-reddit

0.3.0 • Public • Published

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
        }
      }
    }
  }
}

Package Sidebar

Install

npm i gatsby-source-reddit

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

11 kB

Total Files

8

Last publish

Collaborators

  • arjunrao87