-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: specify gql schema to prevent cover inferrence error #36
Conversation
Thanks for the PR! Yes, this is an interesting idea, perhaps it will lead to a solution to the problem. We need to explicitly show that the cover is a file, not a string or anything else. I can’t approve this PR, when I try to use it, the content of the site disappears. I tried various options, but either an error occurs or the content disappears. |
Ah, I'm glad you checked - I can dig more into it later this week |
That would be awesome. Even any intermediate results will be useful. |
Sorry for the delay here - I spent a while looking into this today, I've found quite a few people with these exact symptoms, and always the solution exports.createSchemaCustomization = ({ actions }) => {
const { createTypes, createFieldExtension } = actions;
createTypes(`
type Mdx implements Node {
frontmatter: MdxFrontmatter!
}
type MdxFrontmatter {
cover: File @fileByRelativePath
}
`);
}; If you build this way, you'll see these warnings before many more missing field
The problem is, type inference is not allowed in plugins, because by creating There seem to be workarounds that involve I've updated my PR slightly, to get the type names correct - this gets the front At the broadest perspective, this is a pretty minor issue, and hopefully it can Some relevant issues, if you want to dig any further: |
Thanks for the research @russmatney 👍 Now we at least know what we cannot do. Apparently, at the moment, there is no "elegant" or "right" solution. |
Relevant: #21
I'm new to Gatsby, so am not confident this is the right way to solve
this. In particular, my reading led me to expect to only need to specify
the types down to the
cover
field, while the rest should be inferred.However, doing this led to errors - the other types couldn't be found,
and a few other warnings showed up that might be relevant.
Doesn't feel like the ideal solution, but it solves the error I had, so
I thought I'd at least get this PR open.
Relevant links:
The root of the error is the
cover
field being detected as an emptystring (hence,
String
as the gql type) in some frontmatters before theFile
type can be inferred from another post.Gatsby opened APIs to allow for overriding types like these, but they're
supposed to merge your customized types with the inferred fields
somewhere in the pipeline - that does not appear to be happening here,
not sure why.