I'm fetching data from a strapi Api as Collection, it works but if i make changes in Strapi the data doesn't changes in Gridsome and i have to restart the Gridsome server to get the new info.
Runing Api and Gridsome in local development
I already checked strapi is working and graphql doesn't get the new data.
my code:
gridsome.server.js
const axios = require('axios')
api.loadSource(async actions => {
const { data } = await axios.get('http://localhost:1337/events')
const collection = actions.addCollection({
typeName: 'Event',
path: 'event/:id'
})
for (const event of data) {
collection.addNode({
id: event.id,
title: event.title,
description: event.description,
price: event.price,
date: event.date,
location: event.location,
duration: event.duration,
coverName: event.cover.hash,
coverThumbNail: event.cover.formats.thumbnail.url,
coverMedium: event.cover.formats.medium.url,
coverImage: event.cover.formats.large.url,
category: event.categories,
path: '/events/'+event.id
})
}
})
my index.vue
<page-query> query { events: allEvent{ edges{ node { id title description price date location duration coverName coverThumbNail coverMedium coverImage category { id } } } } } </page-query>
<script>
export default {
data: () => ({
events: []
}),
mounted() {
this.events = this.$page.events.edges
},
}
Thanks for your time