Skip to content
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

Getting error 'Cannot query field "draft" on type "Frontmatter".' #546

Closed
hyphen-wrex opened this issue Nov 10, 2016 · 7 comments
Closed

Comments

@hyphen-wrex
Copy link

hyphen-wrex commented Nov 10, 2016

I cloned Bricolage.io site with Gatsby, develop was working great, except hot reloading wasn't working at all, not big deal I think, it is alpha version overall.

Then I deleted everything except favicon.ico, index.js, robots.txt, tags.js in pages folder to write my own blog posts, wrote couple of them and when I use "gatsby build" in command line, getting this error: 'Cannot query field "draft" on type "Frontmatter".'

Is it possible to workaround this problem? If not, what is the appropriate way to populate Kyle Mathews style blog with my own posts? Or is it simply not possible and I should get things done from scratch using one of Gatsby simple starters?

Update: for someone getting the same error, you should remove draft field from GraphQL queries in following files:

  • page-templates/blog-post.js
  • page-templates/tag-page.js
  • pages/index.js
  • pages/tags.js
@iiroj
Copy link

iiroj commented Nov 11, 2016

I'm getting the same error. Removed all the blog posts, put in my own and was greeted with this. Then I restored all the previous posts and the error continued. I suspect it might be some cache problem.

I think I got finally got around by adding draft: false to my own posts.

This is on 1.0.0-alpha9.

@KyleAMathews
Copy link
Contributor

There hasn't been any time spent on improving the errors in the new stuff so that error is a bit ambiguous. What's happening is in my blog — I add draft: true to frontmatter of draft blog posts. Then Gatsby, with its new GraphQL data layer, constructs a graphql schema based on my blog posts — which because of my draft: true adds draft as a field in the markdown frontmatter type.

The error comes from the fact that the blog index page queries for the draft field (see https://github.com/KyleAMathews/blog/blob/90e9c2979b54f08b76ddd7e9f7101b6ba93d6353/pages/index.js#L79). Gatsby extracts the graphql queries from pages and runs them and then injects their results as props into the component. This lets you query for exactly the data you need for a page. But since you removed the markdown files with draft: true, the schema now doesn't include this as a field which means that the query then fails because the field draft no longer exists.

So the solution would be to modify the queries to remove all mentions of the draft field.

Thanks for checking out the 1.0 stuff! I salute your bravery :-) I'll be starting to work on upgrade + conceptual/API docs soon as I finish fleshing out the final pieces.

@hyphen-wrex
Copy link
Author

@iiroj @KyleAMathews thanks for answers, closing issue.

Offtop: Kyle, did you drop your idea about SimpleGTD? I highly resonate with your concerns you've introduced in your blogpost. I would like to discuss that and compare your ideas with mine :-)

@KyleAMathews
Copy link
Contributor

@hyphen-wrex yeah — 1) didn't think building a TODO app was worth my time and 2) I decided there are better ways to think about productivity e.g. this book and this one

@cupojoe
Copy link
Contributor

cupojoe commented Jun 27, 2018

@KyleAMathews is there a way to manually add a field to the schema, in case you want to keep this functionality but don't have any draft pages at the moment (ie. could be added in the future?)

Edit: solved it by adding the property with a default false to pages. Still wonder if there is a way to declare a schema.

@pieh
Copy link
Contributor

pieh commented Jun 27, 2018

@cupojoe not yet possible - schema is constructed just from existing data. There is defenitely plan to add way to declare schema after Gatsby v2 is released

@chakrihacker
Copy link

you can achieve this by using createNode with a default value

createNodeField({
  node,
  name: 'draft',
  value: draft || false,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants