-
Notifications
You must be signed in to change notification settings - Fork 60
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
Unable to add custom fields #25
Comments
+1 , with disabling the createNodefield( if it is intentional ) took away the quite a lot of the flexibility |
Any updates here? This doesn't seem to be fixed yet, making things more complicated than they could be. |
Just spent two hours this morning trying to debug my build, etc... until finally realizing that this was apparently an issue. I think that if this is an intentional decision it should at least be documented somewhere more obvious. |
You are completely correct @gristleism – we should document this limitation. |
Hi Sanity team, is there a specific reason for this restriction? As marvinwu and zielinsm pointed out this limits a lot of Gatsby’s awesome functionality. Some of our projects make extensive use of Gatsby’s node system and Sanity would be an awesome fit with its dynamic content types. But not being able to actually work on top of the Sanity-created nodes lead to a lengthy debugging session and afterwards to strange workarounds in a test setup. Any chance we can make the custom fields functionality work? |
To clarify: It's not intentional, we just haven't gotten around to fixing this yet. I've put it on the backlog of things to do. No ETA at the moment I'm afraid. |
I agree that this is confusing - especially that you get no error/warning. There is a newer API which you can use to add fields to a type, however: // In your `gatsby-node.js`:
exports.createResolvers = ({createResolvers}) => {
createResolvers({
// `SanityBlogPost` being the type name you want to extend
SanityBlogPost: {
// `happiness` being the field name you want to add
happiness: {
// type is the _GraphQL_ type name, so you can do `String!` for "non-null string", `Int` for integer, `SanityCategory` for a document or object of type `SanityCategory`.
type: 'String',
resolve(source, args, context, info) {
return 'is customization through GraphQL'
}
}
}
})
} There is more info on this API in the Gatsby docs |
Just ran into this issue. @rexxars Thank you! I think that should be added to the docs since |
Per the Sanity Kitchen Sink, you can also use Gatsby's
This has the added benefit of giving you sort and filter functionality for your fields, which doesn't happen when you add them with |
I'm strugging with the same isssue and trying to find workarounds. I'm running the website which should have either Sanity or other CMS integration, and need to unify data schema. Slug field is created using createNodeFiled() for second CMS, and I can't do the same for Sanity (as all other in the topic). I'm trying to map field created by createNodeFiled to something, and can't have access to source.fields object. Have anyone tried to add a resolver where have access to source.fields object? |
@turistua If I'm understanding your question correctly, you can find document fields as properties of
I use I've experienced some race conditions, however these may be a problem with this plugin as opposed to with Gatsby itself (#83), it's hard to say. |
Oh god! 5 hours working :( |
Any updates on this? |
I believe setting infer to false (aka. |
Using
onCreateNode
ingatsby-node
, I’m trying to use a transformer to compile and denormalize some data and then add this new value to the node withcreateNodeField
. The process work fine but thefields
object is not appended on my graphql schema.@rexxars told me (on the Slack channel) that this was intentional, but I really need the ability to transform data at compile time.
The text was updated successfully, but these errors were encountered: