Closed danielfarrell closed 6 years ago
So currently there's an API for extending the graphql types that Gatsby creates. You can see implementations in gatsby-typegen-remark and gatsby-typegen-sharp.
A simplified implementation looks like:
exports.extendNodeType = ({
type,
}) => {
if (type.name !== `TypeToModify`) {
return {}
}
return {
greeter: {
type: GraphQLString,
args: {
name: {
type: GraphQLString,
defaultValue: "Bob",
},
},
resolve(node, { name }) {
return `Hi ${name}!`
},
},
}
}
What this doesn't let you do is create entirely new types. Is that what you'd need? We could easily add a new API hook at https://github.com/gatsbyjs/gatsby/blob/77b15a947be84d24660a88fb30f7dce4aa2329cc/packages/gatsby/lib/schema/index.js#L17 that'd let you mutate things however you want before the schema is created.
I think I would need to create new types for union/interface types, yeah. I could probably change things to live without them if it's not something of interest to others, but that API hook would interest me.
Should I take a stab at implementing it in a PR?
Should I take a stab at implementing it in a PR?
Yes please!
New API hooks are a one liner to add.
Open PR for this @ https://github.com/gatsbyjs/gatsby/pull/2990
Is extendNodeType
deprecated? Is the alternative recommended solution for this problem to use setFieldsOnGraphQLNodeType
?
Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!
Is there a way to add Union types of Interfaces from plugins?