I can't determine how to define types for the Query type Gatsby generates. I want to do this because, by default, Gatsby generates all fields as nullable, making working with Typescript very verbose!
Using the blog starter project, I have the following query:
query {
site {
siteMetadata {
title
description
author
}
}
}
I have defined custom non-nullable types for some data I know will always be present, e.g.,:
gatsby-node.js:
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type Site implements Node {
siteMetadata: SiteSiteMetadata!
}
type SiteSiteMetadata {
title: String!
description: String!
author: String!
}
`
createTypes(typeDefs)
}
I want to define site as non-nullable too, but when I add for example:
type Query {
site: Site!
}
It appears to be overwritten.
TL;DR: Is it possible to define custom fields for the root Query type?
Hiya!
This issue has gone quiet. Spooky quiet. 馃懟
We get a lot of issues, so we currently close issues after 30 days of inactivity. It鈥檚 been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks for being a part of the Gatsby community! 馃挭馃挏
Not stale! 馃憤
Still wondering how to do this :)
Hey again!
It鈥檚 been 30 days since anything happened on this issue, so our friendly neighborhood robot (that鈥檚 me!) is going to close it.
Please keep in mind that I鈥檓 only a robot, so if I鈥檝e closed this issue in error, I鈥檓 HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!
Thanks again for being part of the Gatsby community!
you should be able to use createResolvers to add custom root query fields, see https://www.gatsbyjs.org/docs/schema-customization/#custom-query-fields
Thank you for opening this, @MorrisonCole
We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 馃挏
Most helpful comment
you should be able to use
createResolversto add custom root query fields, see https://www.gatsbyjs.org/docs/schema-customization/#custom-query-fields