feed-module icon indicating copy to clipboard operation
feed-module copied to clipboard

If using Apollo instead of Axios?

Open adamkhan opened this issue 6 years ago • 8 comments

For those of us unable to figure it out, could you explain how we'd gain access to our data for feeds if using Apollo instead of Axios?

adamkhan avatar Sep 05 '18 16:09 adamkhan

I'm sorry but I don’t have experience with Apollo/GraphQL. 😕

But essentially it should work similar to the axios setup (import the package of the „connection agent“, make the request, use the data“). However you have to use plain NPM packages

TheAlexLichter avatar Sep 05 '18 17:09 TheAlexLichter

Thanks for the quick response. I'm just not sure how to go about doing this within nuxt.config.js rather than in a .vue component file. Well, if I figure it out I'll post here.

adamkhan avatar Sep 09 '18 15:09 adamkhan

You are welcome!

Yeah, that's a bit tricky. But there is likely a node apollo client you could use for that, right? :thinking:

TheAlexLichter avatar Sep 09 '18 15:09 TheAlexLichter

I'll look into that.

What might be simpler for me as well, coming from a monolithic CMS background, is the completely different approach of creating a new layout for feeds. Though I'm not sure yet how much of the <head> tag and whether the doctype can be overridden in Nuxt...

adamkhan avatar Sep 09 '18 15:09 adamkhan

Well, you have to provide the feeds somehow :man_shrugging:

With this module, nuxt will take over this job. Attaching feeds into your metadata is not covered but should be easy as you can control the URLs :+1:

TheAlexLichter avatar Sep 09 '18 15:09 TheAlexLichter

Right now this alternative approach to your feed module looks to me not possible in Nuxt, because the doctype is set in the the View, and only one View can be set it seems, ie, the one that shows the web pages, else no web site! See https://nuxtjs.org/guide/views/.

So in order to output a feed without your module, a whole new instance of Nuxt would seem to be required!

adamkhan avatar Sep 11 '18 10:09 adamkhan

Here's an example:

async create (feed) {
        feed.options = {
          title: 'Something',
          description: 'A RSS news feed containing the latest news of Something.',
          link: 'https://www.Something.com/rss.xml',
          feedLinks: {
            atom: 'https://www.Something.com/rss.xml'
          },
          language: 'bn-bd',
          copyright: 'Copyright 2021, Something  Limited',
          creator: 'John Doe',
          author: {
            name: 'Something ([email protected])'
          },
          dc: {
            language: 'bn-bd',
          }
        }
        const feedData = []
        const fetch = require('cross-fetch')
        await fetch(process.env.GQL_API + '/graphql', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({
            query: ` query {
              news {
                news{
                  slug
                  updatedAt
                  title
                  description
                  subtitle
                  author {
                    nameBn
                  }
                  category{
                    name
                  }
                  coverImage
                }
              }
            }`,
            variables: {}
          })
        }).then(res => res.json())
          .then((data) => {
            data.data..forEach((blog) => {
              feedData.push(blog)
            })
          })
        feedData.forEach((blog) => {
          feed.addItem({
            title: blog.title,
            link: process.env.BASEURL + `/news/${new Intl.DateTimeFormat('fr-ca').format(blog.updatedAt).replace('/', '-').replace('/', '-')}/${blog.slug}`,
            description: blog.subtitle + blog.description.replace(/(<([^>]+)>)/ig, '').trim(),
            // description: blog.description,
            published: new Date(parseInt(blog.updatedAt)),
            id: blog.slug,
            source: 'Something Limited',
            creator: blog.author.nameBn,
            content: blog.description,
            image: blog.coverImage,
            media: {
              content: blog.coverImage
            },
            author: [
              {
                name: blog.author.nameBn
              }
            ],
            category: blog.category.name
          })
        })
      },

But the problem is the feed doesnt show in a xml format version, and dc elements dont show.

mimbo119 avatar Jul 15 '21 12:07 mimbo119

https://jsonfeed.org/ is a standard that more readers are handling.

adamkhan avatar Jul 15 '21 23:07 adamkhan