xqsit94 / gridsome-starter-geek-blog

Tech blog boilerplate built with Gridsome
https://gridsome-geek-blog.netlify.app
MIT License
19 stars 8 forks source link

Failing when default posts removed #9

Closed ubionexd closed 2 years ago

ubionexd commented 2 years ago

 error  in ./src/pages/Index.vue?vue&type=custom&index=0&blockType=page-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:14:9
13 |         summary
14 |         thumbnail
   |         ^
15 |         timeToRead
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\page-query.js:33:23)

 @ ./src/pages/Index.vue?vue&type=custom&index=0&blockType=page-query 1:0-409 1:425-428 1:430-836 1:430-836
 @ ./src/pages/Index.vue
 @ ./src/.temp/routes.js
 @ ./node_modules/gridsome/app/router.js
 @ ./node_modules/gridsome/app/entry.sockjs.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

 error  in ./src/templates/Category.vue?vue&type=custom&index=0&blockType=page-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:19:13
18 |             summary
19 |             thumbnail
   |             ^
20 |             categories {
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\page-query.js:33:23)

 @ ./src/templates/Category.vue?vue&type=custom&index=0&blockType=page-query 1:0-412 1:428-431 1:433-842 1:433-842
 @ ./src/templates/Category.vue
 @ ./src/.temp/routes.js
 @ ./node_modules/gridsome/app/router.js
 @ ./node_modules/gridsome/app/entry.sockjs.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

 error  in ./src/templates/Tag.vue?vue&type=custom&index=0&blockType=page-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:19:13
18 |             summary
19 |             thumbnail
   |             ^
20 |             categories {
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\page-query.js:33:23)

 @ ./src/templates/Tag.vue?vue&type=custom&index=0&blockType=page-query 1:0-407 1:423-426 1:428-832 1:428-832
 @ ./src/templates/Tag.vue
 @ ./src/.temp/routes.js
 @ ./node_modules/gridsome/app/router.js
 @ ./node_modules/gridsome/app/entry.sockjs.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

 error  in ./src/pages/Blog.vue?vue&type=custom&index=0&blockType=page-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:19:9
18 |         summary
19 |         thumbnail
   |         ^
20 |         timeToRead
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\page-query.js:33:23)

 @ ./src/pages/Blog.vue?vue&type=custom&index=0&blockType=page-query 1:0-408 1:424-427 1:429-834 1:429-834
 @ ./src/pages/Blog.vue
 @ ./src/.temp/routes.js
 @ ./node_modules/gridsome/app/router.js
 @ ./node_modules/gridsome/app/entry.sockjs.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

 error  in ./src/templates/Post.vue?vue&type=custom&index=0&blockType=page-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:7:5
6 |     sidebar
7 |     thumbnail
  |     ^
8 |     path
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\page-query.js:33:23)

 @ ./src/templates/Post.vue?vue&type=custom&index=0&blockType=page-query 1:0-408 1:424-427 1:429-834 1:429-834
 @ ./src/templates/Post.vue
 @ ./src/.temp/routes.js
 @ ./node_modules/gridsome/app/router.js
 @ ./node_modules/gridsome/app/entry.sockjs.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

 error  in ./src/components/SearchInput.vue?vue&type=custom&index=0&blockType=static-query

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/static-query.js):
Error: Cannot query field "thumbnail" on type "Post".

GraphQL request:10:9
 9 |         summary
10 |         thumbnail
   |         ^
11 |         categories {
    at Object.module.exports (C:\Users\UbiOne\Documents\GitHub\ubionexd.dev\node_modules\gridsome\lib\plugins\vue-components\lib\loaders\static-query.js:38:21)

 @ ./src/components/SearchInput.vue?vue&type=custom&index=0&blockType=static-query 1:0-419 1:435-438 1:440-856 1:440-856
 @ ./src/components/SearchInput.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/babel-loader/lib??ref--1-1!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./node_modules/windicss-webpack-plugin/dist/loaders/windicss-template.cjs!./src/layouts/Default.vue?vue&type=script&lang=js&
 @ ./src/layouts/Default.vue?vue&type=script&lang=js&
 @ ./src/layouts/Default.vue
 @ ./src/main.js
 @ ./node_modules/gridsome/app/app.js
 @ ./node_modules/gridsome/app/entry.client.js
 @ multi webpack/hot/dev-server webpack-hot-middleware/client?name=app&reload=true&noInfo=true ./node_modules/gridsome/app/entry.client.js ./node_modules/gridsome/app/entry.sockjs.js

I had the same problem with is_archived, but I removed it and it worked until now. Now I don't know what to do.

neilherbertuk commented 2 years ago

This happens when you don't have an attribute within any of your post's frontmatter. In this instance you dont have thumbnail in any.

It's still trying to look for these attributes when querying for data but it's failing as it's not in the schema it's generating from any of your markdown posts.

A quick fix is to add the frontmatter attributes it's complaining about to at least one of your posts. Thats the part at the top of your markdown before the ---

Ideally any fields like this need to be added to the schema to prevent this from happening like the one I added for the sidebar within the block starting on line 67 within gridsome.server.js. This provides gridsome a default if its not present in any of your frontmatter like you are seeing.

neilherbertuk commented 2 years ago

Without testing this at all as I'm writing this on a phone. I would guess modifying the gridsome.server.js file to something like this would fix this.

    addSchemaResolvers({ 
       Post: { 
         sidebar: { 
           type: 'String', 
           resolve(obj) { 
             return (obj.sidebar === undefined ? 'Default' : obj.sidebar) 
           } 
         },
         thumbnail: { 
           type: 'String', 
           resolve(obj) { 
             return (obj.thumbnail === undefined ? null : obj.thumbnail) 
           } 
         } 
       } 
     })

I will test this and make a PR when I get a chance, the thumbnail type might need to be something other than a String.

The thumbnail already has a check within the post template to populate it with a default if a thumbnail is not supplied (is null). Unfortunately, if it's not present in any of the frontmatter it can't query it as it won't be part of the schema. If a single entry has one it knows to set those posts without it to null. Adding this makes it part of the schema anyway and gives the thumbnail property a default value of null.

ubionexd commented 2 years ago

Thanks, this worked. It still crashes the developer environment if one of the markdown files is edited, but it restarts without errors.