graphql-engine/community/sample-apps/react-static-graphql/static.config.js
2019-02-08 15:14:35 +05:30

40 lines
1.0 KiB
JavaScript

import client from './src/apollo'
import {GET_AUTHOR, GET_ARTICLE} from './src/graphql/queries'
export default {
getSiteData: () => ({
title: 'React Static with Hasura GraphQL',
}),
getRoutes: async () => {
const {
data: { author },
} = await client.query({
query: GET_AUTHOR,
})
return [
{
path: '/blog',
getData: () => ({author}),
children: author.map(item => ({
path: `/${item.id.toString()}`,
component: 'src/containers/Post',
getData: (resolvedRoute) => {
const path = resolvedRoute.route.path
const author_id = path.split("/")[1]
return client.query({
query: GET_ARTICLE,
variables: {author: author_id}
}).then( (resp) => {
const articles = resp.data.article;
if(articles) {
return {articles}
}
return {articles: []}
})
},
})),
},
]
},
}