I'm trying to build a gatsby website based on gatsby-casper starter but I am getting a hard to debug error related to the graphql schema. The error I get is this:
Error: Type with name "AuthorYaml" does not exists
- TypeStorage.js:44 SchemaComposer.get
[Physicc-blog]/[graphql-compose]/lib/TypeStorage.js:44:13
- TypeMapper.js:585 ThunkComposer._thunk
[Physicc-blog]/[graphql-compose]/lib/TypeMapper.js:585:34
- ThunkComposer.js:20 ThunkComposer.get ofType [as ofType]
[Physicc-blog]/[graphql-compose]/lib/ThunkComposer.js:20:34
- ThunkComposer.js:46 ThunkComposer.getType
[Physicc-blog]/[graphql-compose]/lib/ThunkComposer.js:46:17
- ListComposer.js:22 ListComposer.getType
[Physicc-blog]/[graphql-compose]/lib/ListComposer.js:22:49
- ObjectTypeComposer.js:348 ObjectTypeComposer.getFieldConfig
[Physicc-blog]/[graphql-compose]/lib/ObjectTypeComposer.js:348:18
- index.js:220 forEach
[Physicc-blog]/[gatsby]/src/schema/extensions/index.js:220:48
- Array.forEach
- index.js:215 forEach
[Physicc-blog]/[gatsby]/src/schema/extensions/index.js:215:8
- Array.forEach
- index.js:211 processFieldExtensions
[Physicc-blog]/[gatsby]/src/schema/extensions/index.js:211:32
- schema.js:226 processTypeComposer
[Physicc-blog]/[gatsby]/src/schema/schema.js:226:11
- schema.js:200 map
[Physicc-blog]/[gatsby]/src/schema/schema.js:200:7
- Array.map
- schema.js:199 updateSchemaComposer
[Physicc-blog]/[gatsby]/src/schema/schema.js:199:50
- schema.js:64 buildSchema
[Physicc-blog]/[gatsby]/src/schema/schema.js:64:3
I have used
gatsby new my-gatsby-project https://github.com/scttcper/gatsby-casper
to initialize the project. I'm unable to figure out why this error is being generated.
Well... that starter (gatsby-casper) has a reference to AuthorYaml
in the gatsby-node.js
at line 105:
allAuthorYaml {
edges {
node {
id
}
}
So if you haven't defined that node, your GraphQL query is not able to run, hence the code is breaking.
Pulling more the thread, allAuthorsYaml
is a node created by gatsby-transformer-yaml
, present in gatsby-config.js
(line 64):
'gatsby-transformer-yaml',
And mapped in line 11 of the same gatsby-config.js
file:
mapping: {
'MarkdownRemark.frontmatter.author': 'AuthorYaml',
},
This means that you are creating an AuthorYaml
node from the author field in your markdown frontmatter
.
So, if your markdown frontmatter
doesn't contain an author reference, your code will break. It can be easily fixed by setting the proper author in the markdown file, or just by removing allAuthorYaml
query node from the gatsby-node.js
and all the related references to them like:
// Create author pages
const authorTemplate = path.resolve('./src/templates/author.tsx');
result.data.allAuthorYaml.edges.forEach(edge => {
createPage({
path: `/author/${_.kebabCase(edge.node.id)}/`,
component: authorTemplate,
context: {
author: edge.node.id,
},
});
});
};
From line 188 from gatsby-node.js
file.
The same applies for authorTemplate
since you won't be passing any author in the context your authorTemplate
query will fail too.