-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby): Allow proxying field values from nested fields #16149
Conversation
Changed: pass options via One thing to note (after seeing today's twitch stream): this does not call any field resolvers, which means that proxying to fields on nodes that are linked via foreign-key relation does not work out of the box. Specifically, proxying to a field on a parent node will not work if the If we want this, we could either add another extension option, or -- what i prefer -- compose EDIT: Ok, thinking some more on this, maybe we actually should resolve |
@stefanprobst Yeah, let's resolve from. It makes sense in this case because parent use case is going to be so common. |
Some more thoughts on this:
date: Date @dateformat(formatString: "MMM, DD YYYY")
isoDate: Date @proxy(from: "date") to set a default format for the date field but still have the raw iso date available. If we call the
|
I think proxy child types work well because they allow one to keep all the existing ecosystem without the change. You can attach child to any source plugin generated type. While I really like context idea, it would require all the plugins to provide that functionality, which is a much higher migration cost.
Right. We could add "noResolve" arg to proxy. I know it's hacky :/ Not sure what is a better way to do it. |
I think the alternative is extension composition. This does not necessarily have to look like the |
Is this still true? I.E. I'd like to proxy to an |
Currently we can proxy field values from other fields with the
@proxy(from: "somefield")
extension. Additionally, the@link
and@fileByRelativePath
extensions also accept afrom
argument.However, proxying is limited to the same nesting level, i.e. on
Markdown.frontmatter.somefield
it is only possible to proxy to other frontmatter fields, but not one level up/down.This PR adds that. Example:
We do this with a custom defaultFieldResolver on context - because we cannot modify
info.fieldName
like we do now in@proxy
(we cannot put a dotted path there), and we can also not resolve the fieldValue in@proxy
and modify the first resolver argument, because this interferes with node tracking. The advantage ofcontext.defaultFieldResolver
is that@link
and other field extensions now also understand dottedfrom
paths.