Typed Fields (alpha)
Typed Fields offers a new content querying experience in the Nacelle Storefront API. At this time, Typed Fields is in alpha and is limited to customers who use the Contentful Connector for content ingestion.
The Typed Fields advantage in the Nacelle Storefront GraphQL API
When working with the Nacelle Storefront GraphQL API, developers now have the choice between querying fields
or typedFields
to retrieve content data. This distinction is crucial for those aiming to harness the full power and flexibility of GraphQL their data requests. Let's delve into the distinct advantages of using typedFields
over fields
.
Granular Data Queries with typedFields
Consider a typical content query in the Nacelle Storefront GraphQL API:
query MyContent {
allContent(filter: { first: 1, entryDepth: 3 }) {
edges {
node {
nacelleEntryId
fields
}
}
}
}
The fields
field provides a JSON blob of your content data. This means that when you query fields
, you receive the entirety of your content's data fields in one go, regardless of whether you need all that information or not. The only control over the amount of data that's returned is via the entryDepth
filter parameter, as described in Storefront GraphQL API - Content resolution.
On the other hand, typedFields
is designed to allow for more specific, granular data requests. Instead of receiving a large content payload that you then have to sift through, typedFields
lets you specify exactly which pieces of content data you want.
For instance, suppose that you have an article
-type content type that has a content
field, a title
field, and a relatedArticles
field, among others. Let's say that we want to get the only want the content
and title
of each of the relatedArticles
. With typedFields
, you can directly request just those two pieces of information:
query MyRelatedArticles {
allContent(filter: { first: 1, type: "article" }) {
edges {
node {
nacelleEntryId
typedFields {
... on ArticleFields {
relatedArticles {
nodes {
typedFields {
... on ArticleFields {
content
title
}
}
}
}
}
}
}
}
}
}
Note the use of Inline Fragments to query the ArticleFields
of interest. This is how we access specific content types within the top level of typedFields
. Inline fragments allow us to query multiple types within a single typedFields
query. For example, let's say that a page
-type entry's sections
field could contain heroBanner
, sideBySide
, or blogFeature
-type content:
query MyPageSections {
allContent(filter: { first: 1, type: "page" }) {
edges {
node {
nacelleEntryId
typedFields {
... on PageFields {
sections {
nodes {
typedFields {
... on HeroBannerFields {
title
subtitle
}
... on SideBySideFields {
leftSide
rightSide
}
... on BlogFeatureFields {
title
handle
description
}
}
}
}
}
}
}
}
}
}
Updated 12 days ago