Custom type directives that mimic those such as @infer need an API like createFieldExtension #18810
Replies: 8 comments
-
@stefanprobst amazingly very much in the same vain as my question |
Beta Was this translation helpful? Give feedback.
-
My ask is very similar - with the assumption that the resolvers for these may be passed to Apollo-Link chain to be processed. |
Beta Was this translation helpful? Give feedback.
-
@tbrannam I suspect something like this might be deep enough that it takes a while. As a workaround, I plan to make a field directive Sort of like the [example about drafts)(https://www.bradmcgonigle.com/blog/drafts-for-gatsby). I'm hoping that I can introspect all the types, look for this special field, grab the directive, and see its arguments. |
Beta Was this translation helpful? Give feedback.
-
@tbrannam I struck out...adding a metadata field with a directive to add type metadata didn't work. That information isn't available via queries on the type, e.g. I can get lots of information on the field, but not the directive. Which means I'd need to query an actual document, which defeats the point of introspection. I'll have to move type metadata out of the type system until Gatsby lets me access |
Beta Was this translation helpful? Give feedback.
-
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’s 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! 💪💜 |
Beta Was this translation helpful? Give feedback.
-
I guess my main question is how do you plan to utilize this metadata? It will be available in custom GraphQL resolvers but not in the APIs. For example, your One option to make this metadata more available is to build an intermediate schema (entirely based on type definitions, without inferring). But I think we should collect more usage scenarios to address this properly. |
Beta Was this translation helpful? Give feedback.
-
@vladar Thanks for the response. I come from a CMS background and I want to make a plugin that can be used as a lightweight, Markdown-based CMS. Currently I spread information about content types in different places: This extra metadata would be used in default menus, listings, finding template files, etc. |
Beta Was this translation helpful? Give feedback.
-
That's an interesting (and deal-breaking) point about |
Beta Was this translation helpful? Give feedback.
-
Summary
It's easy to write and register a schema field directive with the
createFieldExtension
action. It doesn't appear that this action works for making a type directive such as the built-in@infer
, which is called during startup and has access toschemaComposer.addDirective
.Note: I'm using
directive
instead ofextension
. Should I be saying "custom type extension"?Basic example
I have a branch in a repo with a
createSchemaCustomization
function that attempts to add ametadata
type directive. It would be used in a type definition such asAuthor
here.Some notes:
locations
is a decoy ascreateFieldExtension
isn't setup to pass that along as the flag which tellsschemaComposer.addDirective
to do different behaviorMotivation
I want custom metadata about types and the GraphQL community has indicated that type directives are the way to do this. In this case, I want, for each type, the plural form to let me know what type to create in
onCreateNode
. If something is in/blogposts/
then I will create aBlogPost
(incomplete implementation )My alternative is to make people maintain two sources of content type definitions: one in GQL and one in regular JS objects.
Beta Was this translation helpful? Give feedback.
All reactions