/graphql-web-feeds

Query web feeds (RSS, Atom, and RDF) with GraphQL

Primary LanguageJavaScriptMIT LicenseMIT

GraphQL Web Feeds

Reconciling old shit with new shit; Query web feeds (RSS, Atom, and RDF) with GraphQL

Contents

  1. What is it?
  2. Try it
  3. Installation
  4. Querying
  5. Configuration
  6. Testing
  7. Troubleshooting

What is it?

Sometimes you gotta make use of an RSS/Atom/RDF web feed. graphql-web-feeds aims to make it easy to do that in your GraphQL API.

Try it

Demo Todo :-(

Features / Roadmap-todo

  • make it do something
  • S3 cache, use S3 expiration to expire based on RSS TTL
  • aggregate multiple feeds into one, sorted by date (at the detriment of speed?)
  • offer an Atom/RDF/RSS Interface type ?

Installation

The package makes the assumption that, because you're using GraphQL, you're probably also using ES6+ and therefore your project handles any necessary transpilation, when required.

First, install the package:

npm install graphql-web-feeds --save

Then, add it to your project's GraphQL schema:

import { GraphQLSchema } from 'graphql/type'
import { feedTypeFactory } from 'web-feeds-graphql'

const simpleField = feedTypeFactory()

const schema = GraphQLSchema({
  query: simpleField,
})
query {
  waitButWhy: feed(url: "http://waitbutwhy.com/feed") {
    title
    link
    description
    items {
      title
      link
      description
    }
  }
}

Single, default feed:

import { GraphQLSchema } from 'graphql/type'
import { feedTypeFactory } from 'web-feeds-graphql'

const feedUrl = 'http://waitbutwhy.com/feed'
const field = feedTypeFactory(feedUrl)

const schema = GraphQLSchema({
  query: field,
})
query {
  feed {
    title
    link
    description
    items {
      title
      link
      description
    }
  }
}

With cache and selected feeds:

import { GraphQLSchema } from 'graphql/type'
import { S3Cache } from 'web-feeds-graphql/cache'
import { feedTypeFactory } from 'web-feeds-graphql'

const cache = new S3Cache({ secret, accesskey, ttl: true, ..etc })
const feeds = {
  waitButWhy: 'http://waitbutwhy.com/feed',
  spacex: 'http://www.space.com/home/feed/site.xml',
}
const field = feedTypeFactory(feeds, cache)

const schema = GraphQLSchema({
  query: field,
})
query {
  waitButWhy: feed(name: waitButWhy) {
    title
    link
    description
    items {
      title
      link
      description
    }
  }
}

Querying

query {
  waitButWhy: feed(url: "http://waitbutwhy.com/feed") {
    title
    link
    description
    items {
      title
      link
      description
    }
  }
}

Configuration

Todo

Custom Feed Caches

Todo

Cache must be an object exposing two methods: get and set

stream get(feedUrl)

async set(feedUrl, feedStream)

Testing

git clone https://github.com/adieuadieu/graphql-web-feeds.git
cd graphql-web-feeds
npm test

FAQ / Troubleshooting

Todo? Todo.