Skip to content

Conversation

bakura10
Copy link
Member

Declarative custom data (https://shopify.dev/beta/next-gen-dev-platform/declarative-custom-data-definitions) will allow to create metafield and metaobject definitions directly in a schema. This is, more or less, what this library was doing for the createFromSchema.

However, declarative custom data offers a lot of advantages:

  • They don't rqeuire the app to perform check or post-install hook, improving performance
  • Schema is kept in sync across all merchants automatically
  • Limits are no longer shared among apps

While the feature is not yet available, I think it will be better to wait for a stable release and integrate with this instead. However, because the schema is no longer available as a const, all the TypeScript magic and schema knowledge can't be done anymore.

One approach I'm considering is bundling a CLI tool to generate various things based on the schema found in the TOML file.

Generating types

Considering a schema, this would generate types for the models. For instance considering this:

[metaobjects.app.payment_messages]
name = "Payment Messages"

[metaobjects.app.payment_messages.fields.payment_type]
name = "Payment Type"
type = "single_line_text_field"
required = true

[metaobjects.app.payment_messages.fields.message]
name = "Message"
type = "single_line_text_field"
required = true

This would generate this:

export type PaymentMessages = {
   paymentType: string;
   message: string;
}

Emitting metadata

The library itself needs to know a few things about the schema. This helps knowing how to optimize queries (for instance, knowing if we must fetch references, what are their type... and so on).

To do that, I think the library should also, from this schema, create a global metadata, that could be re-used by the library:

globalThis.__METAOBJECTS_METADATA__ = {
  '$app:payment_messages': {
     fields: {
       payment_type: 'single_line_text_field',
       message: 'single_line_text_field'
    }
  }
}

When we populate a reference, we would therefore now know the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant