mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
40 lines
1.0 KiB
JavaScript
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: []}
|
|
})
|
|
},
|
|
})),
|
|
},
|
|
]
|
|
},
|
|
}
|