AmazeeLabs / silverback-mono

Silverback Monorepo. Central hub for our open source packages and tooling.
https://silverback.netlify.app
8 stars 7 forks source link

Directives instead of auto-generated types #770

Open pmelab opened 3 years ago

pmelab commented 3 years ago

Current situation

The silverback-gatsby schema extension generates some types and fields based on directives in the schema:

  1. Root-level fields for each type annotated with @entity
  2. id, translations and langcode for each type annotated with @entity
  3. id and items for types annotated with @menu
  4. id and parent for types that are set as item_type in a @menu directive

Problem

The exception are the root-level fields for Gatsby. In my opinion they can stay this way, since they are not used by another system and tightly bound to the implementation, and therefore the application should not be in control and/or use these fields for anything else. I would go as far as marking them as @deprecated

Suggestion

Follow the path that was outlined by the @property directive. Make all fields explicit:

type Page @entity(type: "node", bundle: "page") {
  id: String! @id
  language: @langcode
  translations: [Page!]! @translations
  title: @label
}
type MainMenu @menu(menu_id: "main") {
  id: String! @id
  language: @langcode
  items: [MenuItem!]! @menuItems
}

type MenuItem {
  id: String! @id
  parent: String! @menuParent
  label: String! @label
  url: String! @property(path: "url.value")
}

We could provide the basic API for schema extensions to scan for combinations of certain type and field annotations and generate resolvers based on that. That would make it easier to add directives in the future:

pmelab commented 3 years ago

How I got here: While researching #724 , it occurred to me that we could use the information in the schema.

type Image @gutenberg(blockName: "custom/image") {
  media: Media! @media
  caption: String @property('title')
}

Could already tell a validation step which parts of a block are required.