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.
Overview
Create a utility function that helps users parse metaobject fields. Speed up development processes by helping users move more quickly from metaobject graphql queries to being able to consume the data in their app.
Current Approaches
Right now its common for teams/project to create their own utilities to parse the metaobject query response. Mainly so they can attach field keys directly to their parsedValues. It would be nice to standardize and provide it out the box.
Benefits
Usage
There are two primary ways that this function will be used:
parseMetaobject
helper to get the properly formatted fields.Example Dev Experience
Graph QL Query
The original graphql query for a specific metaobject. This example includes a nested metaobject reference to show how that might be parsed. It'll be common to have nested metaobjects 2-3 levels deep.
Query Result
The unformatted output from the graphql api.
Trigger Function
The user would trigger the utility by passing the metaobject to the function.
Output Option 1
Formatted output transforming fields into parsedFields. The fields within parsedFields will have the exact output of the parseMetafield utility.
Output Option 2
Transform the output to directly attach parsed values to the field keys. This streamlines and makes the data easier to access but does create a discrepency in the data structures between fields within metaobjects and normal fields that were parsed directly with the parseMetafield utility.
Implementation
To implement this we need to do a few things. This draft pr attempts to get the bones in place for these changes. Feedback on approach is more than welcome!
Open Questions
metaobject.parsedFields.hero.parsedValue.parsedFields.title.parsedValue
becomesmetaobject.parsedFields.hero.parsedFields.title
.parseMetaobject(metaobject: value, streamlined: true)
?