Reconciling old shit with new shit; Query web feeds (RSS, Atom, and RDF) with GraphQL
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.
Demo 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 ?
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
}
}
}
query {
waitButWhy: feed(url: "http://waitbutwhy.com/feed") {
title
link
description
items {
title
link
description
}
}
}
Todo
Todo
Cache must be an object exposing two methods: get
and set
stream get(feedUrl)
async set(feedUrl, feedStream)
git clone https://github.com/adieuadieu/graphql-web-feeds.git
cd graphql-web-feeds
npm test