fabien0102 / gatsby-starter

Gatsby 2.0 starter with typescript and many cools dev tools
386 stars 99 forks source link

Cannot read tags group. #71

Closed shockw4ver closed 5 years ago

shockw4ver commented 6 years ago

I deleted three sample posts, and generator new one, and when I get into the /blog/ , it errored me Cannot read property 'group' of null. Entire Error:

./src/pages/blog.tsx.exports.default
src/pages/blog.tsx:24
  21 | }
  22 | 
  23 | export default (props: BlogProps) => {
> 24 |   const tags = props.data.tags.group;
  25 |   const posts = props.data.posts.edges;
  26 |   const { pathname } = props.location;
  27 |   const pageCount = Math.ceil(props.data.posts.totalCount / 10);
shockw4ver commented 6 years ago

Now I found the way to resolve it, but how to extends the graphql-types is the new question...😅 I modified the graphql-types.d.ts file, but still cannot query the new field.

fabien0102 commented 6 years ago

I think that the starter assume that you have some tags, so if you add some tags into your article, it should works ;) (example -> https://github.com/fabien0102/gatsby-starter/blob/master/data/blog/2017-04-18--welcoming/index.md)

Otherwise you can just do:

const tags = props.data.tags ? props.data.tags.group : []

Note: This starter is not really up to date, I need to take some time to go the last gatsby version, but you know, time…

shockw4ver commented 6 years ago

Thanks~ I did so to resolve it and made same changes at others place. Looking forward to enjoy the starter with new gatsby!🤓

i001962 commented 5 years ago

Closing this issue. Works as designed. @shockw4ver if you disagree please comment.