Conversation
Alchemy's IngredientDefinition raises an UnknownAttributeError for rss_title and rss_description, so reading the ingredient definitions of the dummy app's news element fails.
Frontend apps consuming the API have no types for the elements and page layouts a host app defines, so they cannot narrow pages by page layout or elements by name. The alchemy:json_api:generate_types task generates them from the element and page layout definitions, with the attribute types declared next to the attributes in each serializer via typelize, so the serializers stay the single source of the API's shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Frontend apps consuming the API have no types for the elements and page layouts a host app defines, so a typo in an ingredient role or a page layout name only shows up at runtime.
bin/rails alchemy:json_api:generate_typesgenerates a.d.tsfile from the app'selements.ymlandpage_layouts.ymlthat describes the output ofdeserialize, so frontends can writedeserialize<AlchemyPage>(json)and narrow onpage.page_layoutandelement.name, with ingredients narrowed by role, select values as literal unions and nested elements restricted tonestable_elements.The attribute types are declared next to the attributes in each serializer via
typelize, because neither the database schema nor Alchemy's models know them: ingredient fields live in the untypeddataJSON column and many attributes are computed in the serializers. A spec fails whenever a serializer attribute has no declared type (or a declaration outlives its attribute), so the types cannot silently drift from the API. Relationship types are derived from the serializers, includinglazy_load_data, which the deserializer turns intonullunless the relationship was included.Typelizer was considered, but it has no jsonapi-serializer adapter and generates one type per serializer, so it cannot produce the per-definition types that are the point of this feature.
typelizeuses the sameattribute: "type"shape, which keeps a later switch mechanical.The dummy app's
newselement carriedrss_title/rss_description, which Alchemy'sIngredientDefinitionrejects, so they are removed in a separate commit.